Opened 9 years ago

#3811 new defect

Metarecord usage in bindings not detected

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

Description

The following script generated bad C-code:

setCommandLineOptions("-g=MetaModelica -d=noevalfunc");

loadString("
uniontype UT
  record R
    Real x;
  end R;
end UT;

function newR
  input Real x;
  output UT ut = R(x);
end newR;
");

newR(1.0); getErrorString();

The error from the C compiler is:

newR.c:25:32: error: use of undeclared identifier 'UT_R__desc'
  tmpMeta[0] = mmc_mk_box2(3, &UT_R__desc, mmc_mk_real(_x));

It seems like using the record constructor for R in this way is not detected as a use of R, so no metarecord stuff is generated for it. This situation can arise since it's now possible to assign to a record field directly, so it's quite easy to end up with a function like newR and no other uses of the record constructor. A simple workaround is to just add an algorithm section and do an assignment instead.

Change History (0)

Note: See TracTickets for help on using tickets.