Skip to content

Commit a5f5101

Browse files
committed
Only postprocess by-name args
The previous code was buggy in that *all* arguments of a method containing a single by-name argument were post processed.
1 parent 88ab4ef commit a5f5101

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

compiler/src/dotty/tools/dotc/typer/Nullables.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,10 @@ object Nullables with
507507

508508
def recur(formals: List[Type], args: List[Tree]): List[Tree] = (formals, args) match
509509
case (formal :: formalsRest, arg :: argsRest) =>
510-
val arg1 = postProcess(formal.widenExpr.repeatedToSingle, arg)
510+
val arg1 =
511+
if formal.isInstanceOf[ExprType]
512+
then postProcess(formal.widenExpr.repeatedToSingle, arg)
513+
else arg
511514
val argsRest1 = recur(
512515
if formal.isRepeatedParam then formals else formalsRest,
513516
argsRest)
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
-- Error: tests/neg-custom-args/explicit-nulls/byname-nullables1.scala:9:22 --------------------------------------------
2-
9 | if x != null then f(x.fld != null) // error
3-
| ^^^^^^^^^^^^^
4-
| This argument was typed using flow assumptions about mutable variables
5-
| but it is passed to a by-name parameter where such flow assumptions are unsound.
6-
| Wrapping the argument in `byName(...)` fixes the problem by disabling the flow assumptions.
7-
|
8-
| `byName` needs to be imported from the `scala.compiletime` package.
1+
-- Error: tests/neg-custom-args/explicit-nulls/byname-nullables1.scala:10:6 --------------------------------------------
2+
10 | f(x.fld != null) // error
3+
| ^^^^^^^^^^^^^
4+
| This argument was typed using flow assumptions about mutable variables
5+
| but it is passed to a by-name parameter where such flow assumptions are unsound.
6+
| Wrapping the argument in `byName(...)` fixes the problem by disabling the flow assumptions.
7+
|
8+
| `byName` needs to be imported from the `scala.compiletime` package.

tests/neg-custom-args/explicit-nulls/byname-nullables1.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ class C with
66

77
def test() =
88
var x: C | Null = C()
9-
if x != null then f(x.fld != null) // error
9+
if x != null then
10+
f(x.fld != null) // error
11+
require(x.fld != null, "error") // ok

0 commit comments

Comments
 (0)