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

public variable in function without input/output #2730

Closed
thorade opened this issue Nov 22, 2020 · 7 comments · Fixed by #2772
Closed

public variable in function without input/output #2730

thorade opened this issue Nov 22, 2020 · 7 comments · Fixed by #2772
Labels
clarification Specification of feature is unclear, but not incorrect tool-issue Issue in tool(s) - not the specification itself
Milestone

Comments

@thorade
Copy link
Contributor

thorade commented Nov 22, 2020

Dymola check complains about this code:

function myFun1
  input Real x;
  output Real y;
  Real z = 4;
algorithm 
  y := x*z;
end myFun1;

but not about this:

function myFun2
  input Real x;
  output Real y;
  constant Real z = 4;
algorithm 
  y := x*z;
end myFun2;

and also not about this:

function myFun2
  input Real x;
  output Real y;
  parameter Real z = 4;
algorithm 
  y := x*z;
end myFun2;

Is it allowed to have any variable without input/output in the public section? Why would it be allowed if variability is reduced to constant or parameter? For another discussion about parameters in functions, see #1594.

@henrikt-ma
Copy link
Collaborator

While not crystal clear, this restriction from 12.2 seems to imply that all of the functions above are illegal:

Each input formal parameter of the function must be prefixed by the keyword input, and each result formal parameter by the keyword output. All public variables are formal parameters.

I'd find it more clear if it was written like this instead:

… Only input and output formal parameters are allowed in the function's public variable section.

@qlambert-pro
Copy link
Collaborator

The implication of the beginning of section 12.4.4 leads me to the same conclusion as Henrik.

Components in a function can be divided into three groups:

  • Public components which are input formal parameters.
  • Public components which are output formal parameters.
  • Protected components which are local variables, parameters, or constants.

@henrikt-ma
Copy link
Collaborator

The following statement in 12.9 also confirms the current intention:

Components in the public part of an external function declaration shall be declared either as input or output.
[This is just as for any other function. The components in the protected part allow local variables for temporary storage to be declared.]

@HansOlsson HansOlsson added this to the Phone2020-6 milestone Dec 10, 2020
@HansOlsson
Copy link
Collaborator

I agree that there doesn't seem to be anything special for such parameter/constant in function.

@HansOlsson
Copy link
Collaborator

Function public components must be input or output, check MSL.

Agreement.

@HansOlsson HansOlsson added the tool-issue Issue in tool(s) - not the specification itself label Dec 15, 2020
@henrikt-ma
Copy link
Collaborator

This wasn't only a tool issue; had the could actually also have been more clear, see #2730 (comment). Should I prepare a PR?

@henrikt-ma henrikt-ma reopened this Dec 15, 2020
HansOlsson added a commit to HansOlsson/ModelicaSpecification that referenced this issue Dec 16, 2020
@HansOlsson HansOlsson added the clarification Specification of feature is unclear, but not incorrect label Dec 16, 2020
@HansOlsson
Copy link
Collaborator

This wasn't only a tool issue; had the could actually also have been more clear, see #2730 (comment). Should I prepare a PR?

I prepared one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Specification of feature is unclear, but not incorrect tool-issue Issue in tool(s) - not the specification itself
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants