Opened 8 years ago

Last modified 8 years ago

#4300 new defect

MetaModelica type checking fail with function pointers

Reported by: Per Östlund Owned by: Martin Sjölund
Priority: normal Milestone: Future
Component: MetaModelica Version: v1.12.0
Keywords: Cc:

Description

This script fails without any error message:

setCommandLineOptions("-g=MetaModelica");

loadString("
  uniontype U
    record R
      String path;
    end R;

    function name
      input U u;
      output String name = u.path;
    end name;
  end U;

  function typeCheckFail
  protected
    U u = U.R(\"test\");
  algorithm
    print(u.name); // Oops, should've been u.path.
  end typeCheckFail;
"); getErrorString();

typeCheckFail(); getErrorString();

In other words, calling a function expecting e.g. a string with a function pointer just silently fails. Using --showErrorMessages shows nothing, but replacing the argument with e.g. an integer does produce the expected error.

Change History (1)

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

You need to enable -d=gen for this script to work. What's funny is if I enable -d=gen, it actually generates code for it.

It actually seems like... u.name returns a function pointer returning a string and print believes this is the same as something returning a string, so it tries to print the function pointer as if it was a string :)

Note: See TracTickets for help on using tickets.