Opened 7 years ago

Closed 6 years ago

#4786 closed defect (fixed)

Functions are sometimes not type checked when passed as arguments

Reported by: perost Owned by: sjoelund.se
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 perost 7 years ago.

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by perost

comment:1 Changed 6 years ago by sjoelund.se

  • Component changed from MetaModelica to Frontend
  • Owner changed from sjoelund.se to somebody

Function partial application is a standard Modelica feature.

comment:2 Changed 6 years ago by sjoelund.se

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 Changed 6 years ago by sjoelund.se

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

comment:4 Changed 6 years ago by sjoelund.se

  • Milestone changed from Future to 1.13.0
  • Priority changed from critical to blocker

comment:5 Changed 6 years ago by sjoelund.se

  • Owner changed from somebody to sjoelund.se
  • Status changed from new to accepted

comment:6 Changed 6 years ago by sjoelund.se

  • Resolution set to fixed
  • Status changed from accepted to closed
Note: See TracTickets for help on using tickets.