This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Why is PRESUPER special to the typer?

2 replies
Anders Bach Nielsen
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.

Hi

I am again trying to battle the early inits and allowing abstract
val/vars in the early defs, but there is somethink that puzles me, why
is PRESUPER so special regarding the typer? Let me show an example

This little program (with the new early syntax):

trait NeedsXEarly {
val x: Int
super
val s: Int
}

Fails with the following error.

test.scala:2: error: missing parameter type
val x: Int
^
This error is generated in the Namers.scala, in the typeSig method in
the pattern match at line 1114 and down.
So that is the error, but I looked at what the ValDef contain in the
above pattern match by adding this line in the beginning of the case:

println("In namer: " + name + " with flags " + flagsToString(mods.flags)
+ " tpt=" + tpt + ",tpt.isEmpty=" + tpt.isEmpty + ",tpt.isType=" +
tpt.isType + " rhs=" + rhs)

This will print the information in the ValDef, now running the example
again through the compiler I get:

In namer: x with flags tpt=,tpt.isEmpty=true,tpt.isType=true rhs=
test.scala:2: error: missing parameter type
val x: Int
^
In namer: s with flags tpt=Int,tpt.isEmpty=false,tpt.isType=true rhs=
[[syntax trees at end of typer]]// Scala source: test.scala
package {
abstract trait NeedsXEarly extends scala.AnyRef {
def x: ;
def s: Int
}
}

one error found

It is clearly the case that both x and s are abstract vals, but only s
has a concrete type Int and x has an "original type" of int, but why...
because it is a PRESUPER? Does the typer handle that in any special way?

The reason I ask is because I have looked at all the usages of the
PRESUPER flag in the parser, namer and typer and I cant really see why
is should matter that x is a PRESUPER at this stage. The unwanted stuff
(things that are not supposed to be in the PRESUPER part) are rejected
in the parser.

/Anders

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Why is PRESUPER special to the typer?

Hi Anders,

The problem is that early definitions do not see the same environment
as normal ones.
Did you print the trees after parser? Maybe that helps

Anders Bach Nielsen
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Why is PRESUPER special to the typer?

Hi Martin

Thank you for the answer and I have poked a bit more into this. If I
print the tree after parser it shows that my early has no type (see
below), but I dont understand why it cannot find Int, it should be
something primitive.

[[syntax trees at end of parser]]// Scala source: test.scala
package {
abstract trait NeedsXEarly extends scala.AnyRef {
val x;
val s: Int
}
}

If i print the type part of the ValDef in the parser, where I set the
PRESUPER flag, then it shows me that the type is Int (I think this is
the original thing), but already in enterSym in Namers the type is
? Can you give me a little pointer to what is going on here?
or someone else?

/Anders

Martin Odersky wrote:
> Hi Anders,
>
> The problem is that early definitions do not see the same environment
> as normal ones.
> Did you print the trees after parser? Maybe that helps
>

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland