Opened 7 years ago

Closed 7 years ago

#4786 closed defect (fixed)

Functions are sometimes not type checked when passed as arguments

Reported by: Per Östlund Owned by: Martin Sjölund
Priority: blocker Milestone: 1.13.0
Component: Frontend Version: v1.13.0-dev-nightly
Keywords: Cc:

Description

This code should produce an error message, but currently compiles:

function f
  input Integer i;
  input FuncT func;
  
  partial function FuncT
    input String s;
  end FuncT;
algorithm
  func(String(i));
end f;

function wrongType
  input Integer i;
  input Integer i2 = 1;
algorithm
  print(String(i) + "\n");
  print(String(i2) + "\n");
end wrongType;

function test
algorithm
  f(1, wrongType);
end test;

The function signature of wrongType doesn't match what f expects at all, but it seems this isn't checked. The default argument also doesn't seem to be used, and when I run the script it prints a random number for i and 0 for i2. This is pretty bad since it's easy to write code that looks (and should be) correct, but which gives undefined behaviour. The same thing happens when using function partial application instead of just passing the argument as it is.

Attachments (1)

test.mos (487 bytes ) - added by Per Östlund 7 years ago.

Download all attachments as: .zip

Change History (7)

by Per Östlund, 7 years ago

Attachment: test.mos added

comment:1 by Martin Sjölund, 7 years ago

Component: MetaModelicaFrontend
Owner: changed from Martin Sjölund to somebody

Function partial application is a standard Modelica feature.

comment:2 by Martin Sjölund, 7 years ago

This seems to be related to Adrian's changes that function pointers seem to automatically cast their type to the result of the function so we can't check function pointer arguments; only their result types: https://github.com/OpenModelica/OMCompiler/commit/73f37044f4

comment:3 by Martin Sjölund, 7 years ago

Will see if https://github.com/OpenModelica/OMCompiler/pull/2283 breaks any tests (or the library coverage)

comment:4 by Martin Sjölund, 7 years ago

Milestone: Future1.13.0
Priority: criticalblocker

comment:5 by Martin Sjölund, 7 years ago

Owner: changed from somebody to Martin Sjölund
Status: newaccepted

comment:6 by Martin Sjölund, 7 years ago

Resolution: fixed
Status: acceptedclosed
Note: See TracTickets for help on using tickets.