Opened 14 years ago
Last modified 14 years ago
#1328 closed defect (fixed)
Create an error message for recursive short class definitions
Reported by: | Martin Sjölund | Owned by: | Martin Sjölund |
---|---|---|---|
Priority: | low | Milestone: | |
Component: | Version: | ||
Keywords: | Cc: | Martin Sjölund, AlexeyLebedev |
Description
{{{class Env
type Env = Real;
end Env;
class A
type Env = Env.Env;
Env e = 1.0;
end A;}}}
Env will lookup itself.
Change History (8)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
In Inst.instClassdef2, the cases with SCode.DERIVED start with calls to removeSelfReference. Do I understand correctly that, even though self-reference is possible in CLASS_EXTENDS definitions,
a) DERIVED correspond to short definitions (like in this example), and, thus,
b) there must be no self-reference in them?
comment:3 by , 14 years ago
Yes. There should be no self-references in (any) class definitions. Short or otherwise (else the compiler loops).
comment:4 by , 14 years ago
Cases like
{{{class A
extends A.A;
class A
Real x;
end A;
end A;}}}
seem to work fine. Should they also be forbidden?
comment:6 by , 14 years ago
Sorry, what do you mean by self-reference, then?
I used it in the same sense as it is used in the function Inst.removeSelfReference: defining a class className in terms of class className.otherClassName . As I understand, this is OK in extends statements, but not in short class definitions?
comment:7 by , 14 years ago
A self-reference is if lookup of an identifier results in the same class you are trying to instantiate.
For example, class A extends A; end A; results in stack overflow, but should probably generate an error message (or be fixed; one could guard each InstExtends from extending each class more than once by sending it a list). Stack overflow is never acceptable.
Note that type Env = Env.Env; would probably not be possible to fix in this way, as it does not have a class to begin with. So this self-reference needs to be broken.
Something to have a look at if you're bored. Should be easy to solve.