Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to call a function which is defined inside an instantiated record of a class #8428

Closed
sbaetzing opened this issue Jan 17, 2022 · 5 comments · Fixed by #8444
Assignees
Labels
COMP/OMC/Frontend Issue and pull request related to the frontend
Milestone

Comments

@sbaetzing
Copy link

sbaetzing commented Jan 17, 2022

Description

Error when trying to access a class (here a function) via a component through an instance of the component and the record, which holds the function. However, when switching to old Frontend the simulation progresses as expected.

1

Steps to Reproduce

• A function is declared within a record
2
• Within a component an instance of the record is created
3
• An instance of the component is created and the function is called through the instance of the component and the instance of the record
4

• When run in OMEdit, first a translation error occurs
• After that the window occurs, where switching to the old frontend is possible
• The Testcase runs on the old frontend only

Expected Behavior

access should be possible. Backround is that this function will be replaceable later on and might have different implementations. This will be implemented inside an outer component so all components can use a replaceable function which is set inside the instance of the outer component.

Version and OS

  • OpenModelica Version: 1.18 stable
  • OS: Windows 10, 64 bit

Additional Context

Models for minimal example

package ReportLibraryOME
  record RecordWithFunction

    function Function = GetOne;
    annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
          coordinateSystem(preserveAspectRatio=false)));
  end RecordWithFunction;

  function GetOne "Get one"

    input Boolean GetNumber  "True: gets one, else gets zero";

    output Integer y;

  algorithm 

    if GetNumber then
    y:=1;
    else
      y:=0;
    end if;

  end GetOne;

  model Component

    ReportLibraryOME.RecordWithFunction recordWithFunction;

    annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
          coordinateSystem(preserveAspectRatio=false)));
  end Component;

  model Testcase_TC01

    Component instanceComponent;

    Integer int = instanceComponent.recordWithFunction.Function(true);

  end Testcase_TC01;
end ReportLibraryOME;
@perost
Copy link
Member

perost commented Jan 17, 2022

The relevant rule from the specification for looking up a name in the form of A.B.C is:

If not found, and if the first identifier denotes a scalar component, or component[j] where component is an array of components and the indices j can be evaluated at translation time and component[j] is a scalar; and if the composite name is used as a function call, the lookup is also performed among the declared named class elements of the scalar component, and must find a non-operator function. All identifiers of the rest of the name (e.g., B and B.C) must be classes.

So looking up a name on the form component1.component2.function is not allowed. I don't really know the rationale behind that though, it would be a one line change for us to allow it.

@casella casella added this to In progress in Improvements for BR Jan 17, 2022
@casella casella added the COMP/OMC/Frontend Issue and pull request related to the frontend label Jan 17, 2022
@casella casella added this to the 1.19.0 milestone Jan 17, 2022
@casella
Copy link
Contributor

casella commented Jan 17, 2022

So looking up a name on the form component1.component2.function is not allowed. I don't really know the rationale behind that though, it would be a one line change for us to allow it.

I opened #3089 on the Modelica Specification issue tracker. Let's see what is the sentiment there.

@sbaetzing
Copy link
Author

ok thanks for investigations so far. Looking to here from you. Yes exactly no warnings or error in dymola.

@casella
Copy link
Contributor

casella commented Jan 18, 2022

Currently we have a comment from a developer of Maplesim, which also accepts this construct. Let's see what the coordinator says.

@casella casella changed the title Error when trying to call a function which is defined inside an instanciated record of a class Error when trying to call a function which is defined inside an instantiated record of a class Jan 19, 2022
perost added a commit to perost/OpenModelica that referenced this issue Jan 21, 2022
- Allow comp1..compN.class1..classN.function(), previously only
  comp.class1..classN.function() was allowed.

Fixes OpenModelica#8428
@perost
Copy link
Member

perost commented Jan 21, 2022

Since it seems pretty certain that this is meant to be allowed I've changed the NF to allow it in #8444.

perost added a commit to perost/OpenModelica that referenced this issue Jan 21, 2022
- Allow comp1..compN.class1..classN.function(), previously only
  comp.class1..classN.function() was allowed.

Fixes OpenModelica#8428
Improvements for BR automation moved this from In progress to Done Jan 21, 2022
perost added a commit that referenced this issue Jan 21, 2022
- Allow comp1..compN.class1..classN.function(), previously only
  comp.class1..classN.function() was allowed.

Fixes #8428
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
COMP/OMC/Frontend Issue and pull request related to the frontend
Projects
Development

Successfully merging a pull request may close this issue.

3 participants