modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Creative Commons Attribution Share Alike 4.0 International
104 stars 40 forks source link

Ambiguity with "class extends" #462

Closed modelica-trac-importer closed 6 years ago

modelica-trac-importer commented 6 years ago

Reported by stefanv on 29 Nov 2010 15:29 UTC Consider:

class extends C ... end C;

class C ... end C;

I believe this is legal, since there's no requirement of declaration before use in Modelica. Thus, the "class extends C" declaration will declare a new class C which replaces the "class C" declaration in the same scope.

However, what about this?:

class extends C ... end C;

class C ... end C;

class extends C ... end C;

There's nothing in the specification that I can find that disallows "class extends C" a second time. The questions are:

  1. Is this actually legal?

  2. If so, which "class extends" declaration is the "second time"?


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

modelica-trac-importer commented 6 years ago

Modified by dietmarw on 30 Nov 2010 08:18 UTC

modelica-trac-importer commented 6 years ago

Comment by HansOlsson on 30 Nov 2010 10:11 UTC 7.3.1 The class extends Redeclaration Mechanism defines that 'class extends C' replaces an inherited class 'C', i.e. it is intended that 'C' is inherited and not locally defined.

4.2 Double Declaration not Allowed "The name of a declared element shall not have the same name as any other element in its partially flattened enclosing class." --- I would think that it in 7.3.1 could be clarified that 'class extends C' is a declared element with name 'C'; which would make all these examples illegal. There were earlier proposals for 'class extends C' that made that it more obvious.

modelica-trac-importer commented 6 years ago

Comment by stefanv on 30 Nov 2010 12:38 UTC I think I was confused by the ambiguity of the existing text:

A class declaration of the type ‘class extends B(…)’ , where class as usual can be replaced by any other specialized class, replaces the inherited class B with another declaration that extends the inherited class

Yes, B is an inherited class, but that's always true when a class name appears in an extends clause. The existing class B is inherited by the new class B being defined. I think what the text should state somehow, is that B must have been inherited into the class containing the "class extends B(…)" declaration.

modelica-trac-importer commented 6 years ago

Comment by hansolsson on 30 Mar 2016 08:15 UTC Replying to [comment:3 stefanv]:

I think I was confused by the ambiguity of the existing text:

A class declaration of the type ‘class extends B(…)’ , where class as usual can be replaced by any other specialized class, replaces the inherited class B with another declaration that extends the inherited class

Yes, B is an inherited class, but that's always true when a class name appears in an extends clause. The existing class B is inherited by the new class B being defined. I think what the text should state somehow, is that B must have been inherited into the class containing the "class extends B(…)" declaration.

Would adding the last sentence below correct that?

A class declaration of the type ‘class extends B(…)’ , where class as usual can be replaced by any other specialized class, replaces the inherited class B with another declaration that extends the inherited class where the optional class-modification is applied to the inherited class. Inherited B means that the class containing class extends B(...) should also inherit another declaration of B from one of its extends-clauses.

modelica-trac-importer commented 6 years ago

Changelog removed by hansolsson on 30 Mar 2016 08:15 UTC

modelica-trac-importer commented 6 years ago

Comment by hansolsson on 20 Jun 2016 12:53 UTC Slightly modified:

A class declaration of the type ‘class extends B(…)’ , where class as usual can be replaced by any other specialized class, replaces the inherited class B with another declaration that extends the inherited class where the optional class-modification is applied to the inherited class. Inherited B here means that the class containing class extends B(...) should also inherit another declaration of B from one of its extends-clauses. - Language group: In agreement by acclamation.

modelica-trac-importer commented 6 years ago

Comment by hansolsson on 23 Jun 2016 11:40 UTC Scheduled to be added to spec.

modelica-trac-importer commented 6 years ago

Comment by hansolsson on 23 Sep 2016 10:08 UTC Resolved in r9486