diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index ccdbec941166..ac6543ab94e3 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -303,6 +303,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase // need to check instantiability here, because the type of the New itself // might be a type constructor. ctx.typer.checkClassType(tree.tpe, tree.srcPos, traitReq = false, stablePrefixReq = true) + if !nu.tpe.isLambdaSub then + // Check the constructor type as well; it could be an illegal singleton type + // which would not be reflected as `tree.tpe` + ctx.typer.checkClassType(nu.tpe, tree.srcPos, traitReq = false, stablePrefixReq = false) Checking.checkInstantiable(tree.tpe, nu.srcPos) withNoCheckNews(nu :: Nil)(app1) case _ => diff --git a/tests/neg/i12486.scala b/tests/neg/i12486.scala new file mode 100644 index 000000000000..8ae605c43bc8 --- /dev/null +++ b/tests/neg/i12486.scala @@ -0,0 +1,10 @@ +val hello: String = "hello" + +object MyObj { + val a: Int = 123 + val b: Double = 456.789 + val c: String = "ABC" +} + +val stringFromSingleton: String = new hello.type() // error: not a class type +val myObjFromSingleton: MyObj.type = new MyObj.type() // error: not a class type