diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 15 | ||||
-rw-r--r-- | test/files/neg/bug1431.check | 4 | ||||
-rw-r--r-- | test/files/neg/bug1431.scala | 10 |
3 files changed, 26 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 023f170c4b..5bbc0b6430 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -223,15 +223,24 @@ trait Typers extends Modes { /** Check that `tpt` refers to a non-refinement class type */ def checkClassType(tpt: Tree, existentialOK: Boolean, stablePrefix: Boolean) { + def errorNotClass(found: AnyRef) = error(tpt.pos, "class type required but "+found+" found") def check(tpe: Type): Unit = tpe.normalize match { case TypeRef(pre, sym, _) if sym.isClass && !sym.isRefinementClass => - if (stablePrefix && phase.id <= currentRun.typerPhase.id && !pre.isStable) - error(tpt.pos, "type "+pre+" is not a stable prefix") + if (stablePrefix && phase.id <= currentRun.typerPhase.id) { + if (!pre.isStable) + error(tpt.pos, "type "+pre+" is not a stable prefix") + // A type projection like X#Y can get by the stable check if the + // prefix is singleton-bounded, so peek at the tree too. + else tpt match { + case SelectFromTypeTree(qual, _) if !isSingleType(qual.tpe) => errorNotClass(tpt) + case _ => ; + } + } case ErrorType => ; case PolyType(_, restpe) => check(restpe) case ExistentialType(_, restpe) if existentialOK => check(restpe) case AnnotatedType(_, underlying, _) => check(underlying) - case t => error(tpt.pos, "class type required but "+t+" found") + case t => errorNotClass(t) } check(tpt.tpe) } diff --git a/test/files/neg/bug1431.check b/test/files/neg/bug1431.check new file mode 100644 index 0000000000..0ae28eea9d --- /dev/null +++ b/test/files/neg/bug1431.check @@ -0,0 +1,4 @@ +bug1431.scala:8: error: class type required but X#Factory found + def fun[X<:MyTrait with Singleton]() = new X#Factory().value + ^ +one error found diff --git a/test/files/neg/bug1431.scala b/test/files/neg/bug1431.scala new file mode 100644 index 0000000000..aff1dbc014 --- /dev/null +++ b/test/files/neg/bug1431.scala @@ -0,0 +1,10 @@ +object Bug_New { + trait MyTrait { + type Alpha + def the_value : Alpha + class Factory() {def value : Alpha = the_value} + } + + def fun[X<:MyTrait with Singleton]() = new X#Factory().value +} + |