Opened 9 years ago

Closed 9 years ago

#3757 closed defect (fixed)

Record field assignment issue

Reported by: perost Owned by: sjoelund.se
Priority: normal Milestone: Future
Component: MetaModelica Version: v1.9.4-dev-nightly
Keywords: Cc:

Description (last modified by perost)

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 (4)

comment:1 Changed 9 years ago by perost

  • Description modified (diff)

Fixed wrong line numbers.

comment:2 Changed 9 years ago by sjoelund.se

It says cls is a non-single class in the type checking, which is why it fails for some reason.

comment:3 Changed 9 years ago by sjoelund.se

Values.mo loses this information. But we can assume if they are both the same uniontype and one of the sides says this uniontype has only 1 member, we can do the assignment.

comment:4 Changed 9 years ago by perost

  • Resolution set to fixed
  • Status changed from new to closed

It's now working with the changes in af457aa.

Note: See TracTickets for help on using tickets.