Opened 10 years ago

Closed 10 years ago

#3338 closed defect (fixed)

Type mismatch in enumeration types

Reported by: palm86@… Owned by: Per Östlund
Priority: high Milestone: 1.9.3
Component: Frontend Version: trunk
Keywords: Cc:

Description

Hi

The following construct used to work in OpenModelica, but after a recent update does not work anymore. I'm not sure if this is a regression or whether the construct was illegal to begin with.

type Name = enumeration(a, b);
Substance[Name] substances(each index = {i for i in Name});

where Substance has an attribute called "index".

I get the following error:

Error: Type mismatch in binding index = {Name.a, Name.b}, expected subtype of enumeration(a, b), got type enumeration(a, b)[Name].

Change History (3)

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

Component: UnknownFrontend
Milestone: Future1.9.3
Owner: changed from somebody to Per Östlund
Status: newassigned

Invalid each is something that was not legal but OpenModelica used to allow.

I would expect the following to work, but it does not work either:

model M
record Substance
  Name index;
end Substance;
type Name = enumeration(a, b);
Substance[Name] substances(index = {i for i in Name});
end M;

comment:2 by palm86@…, 10 years ago

I've also tried the following, since Name should behave a bit like an array:

model M
record Substance
   Name index;
end Substance;
type Name = enumeration(a, b);
Substance[Name] substances(index = Name);
end M;

but still no luck.

comment:3 by Per Östlund, 10 years ago

Resolution: fixed
Status: assignedclosed

Fixed in e95da2b. The original model with 'each' correctly gives an error, while removing the 'each' works as it should. Your last model also works, although strictly speaking it shouldn't since the spec says that enumeration type names may only be used as dimensions and for loop ranges. But that's a relatively recent addition to the spec, so we still just expand the enumeration type name whenever it's used as an expression.

Note: See TracTickets for help on using tickets.