From fdfa503347b85869363d29ebe9f9dfad5a5004bc Mon Sep 17 00:00:00 2001 From: odersky Date: Tue, 10 Jun 2025 17:49:06 +0200 Subject: [PATCH] Tweak parameter dependency test when typing applications Fixes #23299 --- .../dotty/tools/dotc/typer/Applications.scala | 13 +++++++----- .../test/dotc/pos-test-pickling.excludelist | 1 + tests/neg/i16842.check | 20 ++++--------------- tests/neg/i16842.scala | 2 +- tests/pos/i23266.scala | 17 ++++++++++++++++ 5 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 tests/pos/i23266.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index de31936b6e42..b56bf79167a3 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -726,11 +726,14 @@ trait Applications extends Compatibility { def addTyped(arg: Arg): List[Type] = if !formal.isRepeatedParam then checkNoVarArg(arg) addArg(typedArg(arg, formal), formal) - if methodType.isParamDependent && typeOfArg(arg).exists then - // `typeOfArg(arg)` could be missing because the evaluation of `arg` produced type errors - formals1.mapconserve(safeSubstParam(_, methodType.paramRefs(n), typeOfArg(arg))) - else - formals1 + if methodType.looksParamDependent + // need to handle also false dependencies since we generate TypeTrees from + // formal parameters in makeVarArg. These are not de-aliased, so they might contain + // stray parameter references. Test case is i23266.scala. + && typeOfArg(arg).exists + // `typeOfArg(arg)` could be missing because the evaluation of `arg` produced type errors + then formals1.mapconserve(safeSubstParam(_, methodType.paramRefs(n), typeOfArg(arg))) + else formals1 def missingArg(n: Int): Unit = fail(MissingArgument(methodType.paramNames(n), methString)) diff --git a/compiler/test/dotc/pos-test-pickling.excludelist b/compiler/test/dotc/pos-test-pickling.excludelist index 28bce963bfd1..1a0be6f66183 100644 --- a/compiler/test/dotc/pos-test-pickling.excludelist +++ b/compiler/test/dotc/pos-test-pickling.excludelist @@ -139,6 +139,7 @@ parsercombinators-new-syntax.scala hylolib-deferred-given hylolib-cb hylolib +i23266.scala # typecheckErrors method unpickling i21415.scala diff --git a/tests/neg/i16842.check b/tests/neg/i16842.check index 8cad4bc7656f..936b08f95dbb 100644 --- a/tests/neg/i16842.check +++ b/tests/neg/i16842.check @@ -1,16 +1,4 @@ --- [E007] Type Mismatch Error: tests/neg/i16842.scala:24:8 ------------------------------------------------------------- -24 | Liter(SemanticArray[SemanticInt.type], x) // error // error - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | Found: Int => SemanticArray[SemanticInt.type] - | Required: SemanticArray[SemanticType] - | - | longer explanation available when compiling with `-explain` --- [E007] Type Mismatch Error: tests/neg/i16842.scala:24:41 ------------------------------------------------------------ -24 | Liter(SemanticArray[SemanticInt.type], x) // error // error - | ^ - | Found: (x : List[Expr2[SemanticInt.type]]) - | Required: ty.T - | Note that implicit conversions were not tried because the result of an implicit conversion - | must be more specific than ty.T - | - | longer explanation available when compiling with `-explain` +-- Error: tests/neg/i16842.scala:24:7 ---------------------------------------------------------------------------------- +24 | Liter(SemanticArray[SemanticInt.type], x) // error + | ^ + | invalid new prefix (dim: Int): SemanticArray[SemanticInt.type] cannot replace ty.type in type ty.T diff --git a/tests/neg/i16842.scala b/tests/neg/i16842.scala index 1e7e5cc14339..e9935b46c01d 100644 --- a/tests/neg/i16842.scala +++ b/tests/neg/i16842.scala @@ -21,5 +21,5 @@ def typecheckArrayLiter( a: ArrayLiter ): Liter[SemanticArray[SemanticType]] = { val x: List[Expr2[SemanticInt.type]] = List() - Liter(SemanticArray[SemanticInt.type], x) // error // error + Liter(SemanticArray[SemanticInt.type], x) // error } diff --git a/tests/pos/i23266.scala b/tests/pos/i23266.scala new file mode 100644 index 000000000000..bc643ac7215d --- /dev/null +++ b/tests/pos/i23266.scala @@ -0,0 +1,17 @@ + +def kek(t: Table, ids: t.Id*) = ??? + +trait Table { + type Id = String +} + +object Table1 extends Table { + val id: Id = "table1_id" +} + +class Table2() extends Table { + val id: Id = "table2_id" +} + +val x = kek(Table1, Table1.id) +val y = kek(Table2(), Table2().id) \ No newline at end of file