﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3757	Record field assignment issue	Per Östlund	Martin Sjölund	"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 [https://github.com/perost/OMCompiler/tree/nfinst2 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:
{{{#!mo
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):
{{{#!mo
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."	defect	closed	normal	Future	MetaModelica	v1.9.4-dev-nightly	fixed		
