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

Uninitialized fields of record outputs of functions #1628

Closed
modelica-trac-importer opened this issue Jan 15, 2017 · 8 comments
Closed

Uninitialized fields of record outputs of functions #1628

modelica-trac-importer opened this issue Jan 15, 2017 · 8 comments
Assignees
Labels
bug Critical/severe issue L: Media Issue addresses Modelica.Media
Milestone

Comments

@modelica-trac-importer
Copy link

Reported by stefanv on 10 Dec 2014 17:34 UTC
Modelica.Media.Water.waterBaseProp_pT returns a record of type Modelica.Media.Common.IF97BaseTwoPhase.

The function handles four different "regions", and in the if-statement branches for those, it doesn't always assign all of the fields of the output record.

Does that make it an incorrect function? If not, what are the returned values of those fields?

Here's a simplified example:

record R
    Real a, b, c;
end R;

function F
    input Integer region;
    output R rec;
algorithm
    if region == 1 then
        rec.a := 1;
        rec.b := 2;
    else
        rec.b := 3;
        rec.c := 4;
    end if;
end F;

For the call, r = F(1), what is the value of r.a ?


Migrated-From: https://trac.modelica.org/Modelica/ticket/1628

@modelica-trac-importer
Copy link
Author

Comment by hubertus on 10 Dec 2014 18:50 UTC
Hi Stefan,

This code was created when Modelica was at version 1.6 and never updated, keep that in mind. I think that all fields should be initialized, so this could be filed as a but for MSL. 

In this particular case it would be great to have a symbolic UNDEFINED, as has been discussed elswehere. What to do with such record entries is maybe worthwhile discussing in the language group. It may be an option to leave it without assignment, I'd prefer to set a symbolic undefined.

Hubertus

@modelica-trac-importer
Copy link
Author

Comment by jmattsson on 11 Dec 2014 08:34 UTC
The spec says:
The local variables of a function are not automatically initialized to the implicit default values of the data type (Section ‎12.4.4) ![(e.g. 0.0 for Real) for performance reasons. It is the responsibility of the user to provide explicit defaults or to define the values of such variables before they are referenced.!]
I'd say that it would probably be a good idea to detect uninitialized variables in functions with a simple program flow analysis, give a diagnostic and initialize it to the default value anyway. The first two are tool issues, but the last probably needs a spec update to be allowed.

The same issue occures in Modelica.Electrical.Spice3.Internal.Diode.diodeCalcTempDependencies - out_c.m_tBrkdwnV is left unassigned for some cases.

@modelica-trac-importer
Copy link
Author

Comment by hansolsson on 23 Feb 2015 17:19 UTC
Modelica design:
Library should be updated.

The Modelica function should assign to the entire output, including all fields of it (excluding empty arrays - i.e. all elements of the array should be assigned, not the array).

A tool could use NaN, and invalid pointer for strings to be able to detect it (not as easy for Boolean, Integer, and Enumeration - could use invalid values for Boolean and Enumeration). On the other hand to just run predictably it is better to use zero/empty string/false.

@modelica-trac-importer
Copy link
Author

Modified by beutlich on 19 Mar 2015 09:49 UTC

@modelica-trac-importer modelica-trac-importer removed this from the Design85 milestone Jan 15, 2017
@modelica-trac-importer
Copy link
Author

Modified by stefanv on 30 Sep 2015 11:57 UTC

@modelica-trac-importer modelica-trac-importer added this to the MSL3.2.2 milestone Jan 15, 2017
@modelica-trac-importer
Copy link
Author

Comment by hubertus on 13 Dec 2015 01:38 UTC
Fixedin 6dcfe04 n trunk

@modelica-trac-importer
Copy link
Author

Changelog modified by hubertus on 13 Dec 2015 01:38 UTC
Missing initialization fixed in Water IF97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Critical/severe issue L: Media Issue addresses Modelica.Media
Projects
None yet
Development

No branches or pull requests