diff options
author | Martin Odersky <odersky@gmail.com> | 2013-12-09 11:15:25 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-12-09 11:15:25 +0100 |
commit | a53101c6fc3f06fed881e22736d134f6e7893ae0 (patch) | |
tree | e8d6878d9642a42c5e92e8546e4403aedcb12f3e | |
parent | 34993a55387b381dc9e2e754d7179f0385974abd (diff) | |
download | dotty-a53101c6fc3f06fed881e22736d134f6e7893ae0.tar.gz dotty-a53101c6fc3f06fed881e22736d134f6e7893ae0.tar.bz2 dotty-a53101c6fc3f06fed881e22736d134f6e7893ae0.zip |
Fixes to inherited result types in Namer.
-rw-r--r-- | src/dotty/tools/dotc/core/transform/Erasure.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 23 | ||||
-rw-r--r-- | test/dotc/tests.scala | 1 | ||||
-rw-r--r-- | tests/pos/inferred.scala | 5 | ||||
-rw-r--r-- | tests/pos/sigs.scala | 21 |
5 files changed, 37 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/core/transform/Erasure.scala b/src/dotty/tools/dotc/core/transform/Erasure.scala index 1b86eff68..9b118dfe7 100644 --- a/src/dotty/tools/dotc/core/transform/Erasure.scala +++ b/src/dotty/tools/dotc/core/transform/Erasure.scala @@ -126,7 +126,7 @@ object Erasure { sigName(tp1) case OrType(tp1, tp2) => lubClass(tp1, tp2).name - case ErrorType => + case ErrorType | WildcardType => tpnme.WILDCARD } diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 3a05e6038..2d683f37f 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -312,13 +312,16 @@ class Namer { typer: Typer => /** The type signature of a ClassDef with given symbol */ def classDefSig(cdef: TypeDef, cls: ClassSymbol)(implicit ctx: Context): Type = { - //todo: normalize parents, so that all mixins extend superclass + + /** The type of a parent constructor. Types constructor arguments + * only if parent type contains uninstantiated type parameters. + */ def parentType(constr: untpd.Tree): Type = { val (core, targs) = stripApply(constr) match { case TypeApply(core, targs) => (core, targs) case core => (core, Nil) } - val Select(New(tpt), _) = core + val Select(New(tpt), nme.CONSTRUCTOR) = core val targs1 = targs map (typedAheadType(_)) val ptype = typedAheadType(tpt).tpe appliedTo targs1.tpes if (ptype.uninstantiatedTypeParams.isEmpty) ptype @@ -346,8 +349,6 @@ class Namer { typer: Typer => def adjustIfModule(sig: Type): Type = if (denot is Module) sig match { - case sig: TypeRef => - sig case sig: ClassInfo => sig.derivedClassInfo(selfInfo = sig.prefix select sourceModule) case _ => @@ -385,9 +386,7 @@ class Namer { typer: Typer => val pt = if (!mdef.tpt.isEmpty) WildcardType else { - lazy val schema = paramFn(WildcardType) - val site = sym.owner.thisType - val inherited = { + val inherited = if ((sym is Param) && sym.owner.isSetter) { // fill in type from getter result type val getterCtx = ctx.outersIterator .dropWhile(_.owner != sym.owner) @@ -396,17 +395,19 @@ class Namer { typer: Typer => getterCtx.denotNamed(sym.owner.asTerm.name.setterToGetter).info.widenExpr } else if (sym.owner.isTerm) NoType - else + else { // TODO: Look only at member of supertype instead? + lazy val schema = paramFn(WildcardType) + val site = sym.owner.thisType ((NoType: Type) /: sym.owner.info.baseClasses.tail) { (tp, cls) => val itpe = cls.info .nonPrivateDecl(sym.name) .matchingDenotation(site, schema) - .asSeenFrom(site) .info.finalResultType + .asSeenFrom(site, cls) tp & itpe } - } + } def rhsType = adapt(typedAheadExpr(mdef.rhs), WildcardType).tpe.widen def lhsType = fullyDefinedType(rhsType, "right-hand side", mdef.pos) inherited orElse lhsType @@ -437,7 +438,7 @@ class Namer { typer: Typer => else monotpe } if (isConstructor) { - // set result type tree to unit, but set the current class as result type of the symbol + // set result type tree to unit, but take the current class as result type of the symbol typedAheadType(ddef.tpt, defn.UnitType) wrapMethType(sym.owner.typeRef.appliedTo(typeParams map (_.typeRef))) } diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index d680435c4..72c708363 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -25,6 +25,7 @@ class tests extends CompilerTest { @Test def pos_typedapply() = compileFile(posDir, "typedapply") @Test def pos_nameddefaults() = compileFile(posDir, "nameddefaults") @Test def pos_desugar() = compileFile(posDir, "desugar") + @Test def pos_sigs() = compileFile(posDir, "sigs") @Test def neg_blockescapes() = compileFile(negDir, "blockescapesNeg", xerrors = 2) @Test def neg_typedapply() = compileFile(negDir, "typedapply", xerrors = 4) diff --git a/tests/pos/inferred.scala b/tests/pos/inferred.scala index 441ae9650..525848541 100644 --- a/tests/pos/inferred.scala +++ b/tests/pos/inferred.scala @@ -16,13 +16,12 @@ object NIL extends LIST[Nothing] { def tail = ??? } -class CONS[T](hd: T, tl: LIST[T]) extends LIST[T] { +class CONS[U](hd: U, tl: LIST[U]) extends LIST[U] { def isEmpty = false - def head = hd + def head: U = hd def tail = tl } - object Inferred { def foo[T](x: T): T = x diff --git a/tests/pos/sigs.scala b/tests/pos/sigs.scala new file mode 100644 index 000000000..4b91015ee --- /dev/null +++ b/tests/pos/sigs.scala @@ -0,0 +1,21 @@ +object sigs { + + var x = 7 * 9 + + class Base { + + def foo(x: Int): Any = 33 + + def foo: Object = "x" + + } + + class Sub extends Base { + + override def foo = "abc" + + override def foo(x: Int) = "abc" + } + + +}
\ No newline at end of file |