Opened 9 years ago

Closed 4 years ago

#3469 closed defect (fixed)

Conditional declarations doesn't work with inner/outer components

Reported by: Maksimov Doe Owned by: somebody
Priority: high Milestone: 1.16.0
Component: New Instantiation Version:
Keywords: Cc:

Description

model Ex
  inner parameter Boolean enabled = true;
  class Foo
    outer parameter Boolean enabled;
    parameter Integer y if enabled;
  end Foo;
  Foo foo;
end Ex;

Error: The conditional expression enabled could not be evaluated.

Change History (4)

in reply to:  description comment:1 by Maksimov Doe, 9 years ago

I have found that wrapper class can be used as a workaround.

model Ex
  record Config
    parameter Boolean enabled = true;
  end Config;

  class Foo
    outer Config config;
    parameter Integer y if config.enabled;
  end Foo;

  inner Config config;
  Foo foo;
end Ex;

comment:2 by Sam.Lishak@…, 9 years ago

This model is similar but gives a slightly nastier looking error message.

package OMTest
  model BaseModel
    parameter Boolean enabled = true;
    inner parameter Integer test=2 if enabled;
    SubModel sub;
  end BaseModel;

  model SubModel
    outer parameter Integer test=3;
  end SubModel;
end OMTest;

Translating BaseModel gives the following error:

[OMTest: 4:5-4:48]: Type error in conditional 'enabled'. Expected Boolean, got #T_UNKNOWN#.
Error occurred while flattening model OMTest.BaseModel

comment:3 by Sam.Lishak@…, 9 years ago

And trying to use the record workaround results in yet another odd message:

model BaseModel
  record Config
    parameter Boolean sw = true;
  end Config;

  model SubModel
    outer parameter Boolean test = false;
  end SubModel;

  SubModel sub;
  Config config;
  inner parameter Boolean test = true if config.sw;
end BaseModel;
[OMTest: 13:5-13:58]: Variable config.sw not found in scope OMTest.BaseModel.
Error occurred while flattening model OMTest.BaseModel

Yet config.sw should be available in this scope (confirmed by successfully translating the following model):

model BaseModel
  record Config
    parameter Boolean sw = true;
  end Config;

  model SubModel
    outer parameter Boolean test = false;
  end SubModel;

  SubModel sub;
  Config config;
  inner parameter Boolean test = config.sw;
end BaseModel;

comment:4 by Per Östlund, 4 years ago

Component: FrontendNew Instantiation
Milestone: Future1.16.0
Resolution: fixed
Status: newclosed

All the examples work or give correct error messages with the new frontend.

Note: See TracTickets for help on using tickets.