Skip to content

Commit 778e37c

Browse files
Merge pull request #12580 from dotty-staging/fix-12486
Fix checking of `new` to rule out singletons
2 parents 689625d + 47be6bc commit 778e37c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
303303
// need to check instantiability here, because the type of the New itself
304304
// might be a type constructor.
305305
ctx.typer.checkClassType(tree.tpe, tree.srcPos, traitReq = false, stablePrefixReq = true)
306+
if !nu.tpe.isLambdaSub then
307+
// Check the constructor type as well; it could be an illegal singleton type
308+
// which would not be reflected as `tree.tpe`
309+
ctx.typer.checkClassType(nu.tpe, tree.srcPos, traitReq = false, stablePrefixReq = false)
306310
Checking.checkInstantiable(tree.tpe, nu.srcPos)
307311
withNoCheckNews(nu :: Nil)(app1)
308312
case _ =>

tests/neg/i12486.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
val hello: String = "hello"
2+
3+
object MyObj {
4+
val a: Int = 123
5+
val b: Double = 456.789
6+
val c: String = "ABC"
7+
}
8+
9+
val stringFromSingleton: String = new hello.type() // error: not a class type
10+
val myObjFromSingleton: MyObj.type = new MyObj.type() // error: not a class type

0 commit comments

Comments
 (0)