Opened 9 years ago

Last modified 9 years ago

#3757 closed defect

Record field assignment issue — at Version 1

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

Description (last modified by Per Östlund)

I've encountered an issue when assigning to a record field, possibly related to using the UnionType.Record style of referencing a uniontype record together with singleton types. I haven't been able to make a small example that shows the issue, so see perost/nfinst2 instead.

The issue is that NFComponent.Component.COMPONENT has a field classInst, which is of type NFInstNode.InstNode. InstNode contains only one record INST_NODE. In NFInst.instComponentBinding there's then this code:

591:  _ := match component
592:    local
593:      InstNode cls;
594:
595:    case Component.COMPONENT(classInst = cls)
596:      algorithm
597:        (cls, tree) := instBindings(component.classInst, tree);
598:        component.classInst := cls;

This gives an error when compiling:

[NFInst.mo:598:9-598:35:writable] Error: Type mismatch in assignment in component.classInst := cls of NFInstNode.InstNode.INST_NODE := NFInstNode.InstNode
[NFInst.mo:598:9-598:35:writable] Error: Type mismatch in pattern component.classInst
expression type:
  NFInstNode.InstNode
pattern type:
  NFInstNode.InstNode.INST_NODE

One workaround is to rewrite the code like this to fool the compiler into thinking that cls is also an INST_NODE record (which it is of course):

case Component.COMPONENT(classInst = cls as InstNode.INST_NODE())

Adding another dummy record to InstNode also works, so the issue seems to be caused by InstNode being a singleton type.

Change History (1)

comment:1 by Per Östlund, 9 years ago

Description: modified (diff)

Fixed wrong line numbers.

Note: See TracTickets for help on using tickets.