File tree 4 files changed +42
-11
lines changed
compiler/src/dotty/tools/dotc/typer
4 files changed +42
-11
lines changed Original file line number Diff line number Diff line change @@ -4412,7 +4412,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4412
4412
if ! tree.tpe.isErroneous
4413
4413
&& ! ctx.isAfterTyper
4414
4414
&& ! tree.isInstanceOf [Inlined ]
4415
- && isPureExpr(tree)
4416
4415
&& ! isSelfOrSuperConstrCall(tree)
4417
4416
then tree match
4418
4417
case closureDef(meth)
@@ -4425,7 +4424,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4425
4424
// if the original tree was a lambda. This does not work always either since
4426
4425
// sometimes we do not have the original anymore and use the transformed tree instead.
4427
4426
// But taken together, the two criteria are quite accurate.
4428
- missingArgs(tree, tree.tpe.widen)
4427
+ if isPureExpr(tree) then
4428
+ missingArgs(tree, tree.tpe.widen)
4429
+ else
4430
+ report.warning(UnusedNonUnitValue (tree.tpe))
4429
4431
case _ if isUnitExpr =>
4430
4432
report.warning(PureUnitExpression (original, tree.tpe), original.srcPos)
4431
4433
case _ =>
Original file line number Diff line number Diff line change
1
+ -- [E178] Type Error: tests/neg/i19266.scala:13:4 ----------------------------------------------------------------------
2
+ 13 | fn2(2) // error
3
+ | ^^^^^^
4
+ | missing argument list for value of type String => Some[String]
5
+ |
6
+ | longer explanation available when compiling with `-explain`
7
+ -- [E178] Type Error: tests/neg/i19266.scala:19:4 ----------------------------------------------------------------------
8
+ 19 | fn3(4) // error
9
+ | ^^^^^^
10
+ | missing argument list for value of type Double => Some[String]
11
+ |
12
+ | longer explanation available when compiling with `-explain`
13
+ -- [E129] Potential Issue Warning: tests/neg/i19266.scala:9:4 ----------------------------------------------------------
14
+ 9 | fn1(1) // warn
15
+ | ^^^
16
+ | A pure expression does nothing in statement position
17
+ |
18
+ | longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change
1
+ object i19266 :
2
+ def fn1 (x : Int , y : String = " y" )(z : Double ) = Some (s " $x$y$z" )
3
+ def fn2 (p : Int )(q : String ) = Some (s " $p$q" )
4
+ def fn3 (x : Int , y : => String = " y" )(z : Double ) = Some (s " $x$y$z" )
5
+
6
+ def checkCompile =
7
+ // It compiles because default value for by-value
8
+ // parameter is impure and may perform side effect.
9
+ fn1(1 ) // warn
10
+ // This does not compile because (pure) synthesized lambda from
11
+ // eta-expansion in statement position is prohibited.
12
+ // See https://github.com/lampepfl/dotty/pull/11769
13
+ fn2(2 ) // error
14
+ // This compiles.
15
+ val a = fn2(3 )
16
+ // This does not compile because default value for by-name parameter
17
+ // is still pure. Thus, it also violates the rule for lambda in
18
+ // statement position.
19
+ fn3(4 ) // error
20
+ 1
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments