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)
Change History (7)
by , 7 years ago
comment:1 by , 7 years ago
Component: | MetaModelica → Frontend |
---|---|
Owner: | changed from | to
comment:2 by , 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 , 7 years ago
Will see if https://github.com/OpenModelica/OMCompiler/pull/2283 breaks any tests (or the library coverage)
comment:4 by , 7 years ago
Milestone: | Future → 1.13.0 |
---|---|
Priority: | critical → blocker |
comment:5 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → accepted |
comment:6 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
Function partial application is a standard Modelica feature.