File tree 2 files changed +22
-0
lines changed
compiler/src/dotty/tools/dotc/transform 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -250,9 +250,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
250
250
}
251
251
}
252
252
253
+ def checkNoConstructorProxy (tree : Tree )(using Context ): Unit =
254
+ if tree.symbol.is(ConstructorProxy ) then
255
+ report.error(em " constructor proxy ${tree.symbol} cannot be used as a value " , tree.srcPos)
256
+
253
257
override def transform (tree : Tree )(using Context ): Tree =
254
258
try tree match {
255
259
case tree : Ident if ! tree.isType =>
260
+ checkNoConstructorProxy(tree)
256
261
tree.tpe match {
257
262
case tpe : ThisType => This (tpe.cls).withSpan(tree.span)
258
263
case _ => tree
@@ -263,6 +268,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
263
268
withMode(Mode .Type )(super .transform(tree))
264
269
}
265
270
else
271
+ checkNoConstructorProxy(tree)
266
272
transformSelect(tree, Nil )
267
273
case tree : Apply =>
268
274
val methType = tree.fun.tpe.widen
Original file line number Diff line number Diff line change
1
+
2
+ object Test extends App {
3
+ class A {
4
+ class A22 (s : String ) {
5
+ def run = s
6
+ }
7
+ }
8
+ val a = A ()
9
+ val x = a.A22 (" x" ) // OK
10
+ val x2 = a.A22 .apply(" X" ) // OK
11
+ val x3 = a.A22 .apply(_) // OK
12
+ val y = a.A22 // error: Cannot be used as value
13
+ val z = a.A22 .toString // error: Cannot be used as value
14
+ val u = A // error: Cannot be used as value
15
+ println(y)
16
+ }
You can’t perform that action at this time.
0 commit comments