Skip to content

Commit 5525b0c

Browse files
OlivierBlanvillainMasseGuillaume
authored andcommitted
Fix corner case w types ALL passed by name & out of order
This commit removes a problematic duplicated `checkBounds` call on `TypeApply`. To verify correctness of this change on has to check that `normalizeTree` used only once [1], and the function using `normalizeTree` already takes care of calling `checkBounds`. [1]: https://github.com/lampepfl/dotty/blob/0e8f05d88bfef95fac59f522fd9d06792126bd11/src/dotty/tools/dotc/transform/PostTyper.scala#L205
1 parent 504b1f8 commit 5525b0c

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
9393
*
9494
* should behave differently.
9595
*
96-
* O1.x should have the same effect as { println("43"; 42 }
96+
* O1.x should have the same effect as { println("43"); 42 }
9797
*
9898
* whereas
9999
*
@@ -103,10 +103,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
103103
* purity of the prefix unless the selection goes to an inline val.
104104
*/
105105
private def normalizeTree(tree: Tree)(implicit ctx: Context): Tree = tree match {
106-
case tree: TypeTree => tree
107-
case TypeApply(fn, args) =>
108-
Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
109-
tree
106+
case _: TypeTree | _: TypeApply => tree
110107
case _ =>
111108
if (tree.isType) {
112109
Checking.typeChecker.traverse(tree)

src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object Checking {
3737
* well as for AppliedTypeTree nodes. Also checks that type arguments to
3838
* *-type parameters are fully applied.
3939
*/
40-
def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type)(implicit ctx: Context) = {
40+
def checkBounds(args: List[tpd.Tree], boundss: List[TypeBounds], instantiate: (Type, List[Type]) => Type)(implicit ctx: Context): Unit = {
4141
(args, boundss).zipped.foreach { (arg, bound) =>
4242
if (!bound.isHK && arg.tpe.isHK)
4343
ctx.error(ex"missing type parameter(s) for $arg", arg.pos)

tests/pos/t1513b.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
object Test {
2-
def f[T1 <: String, T2 <: Int, T3 <: Boolean](a1: T1, a2: T2, a3: T3) = ()
2+
def f[
3+
T1 <: String,
4+
T2 <: Int,
5+
T3 <: Boolean
6+
](a1: T1, a2: T2, a3: T3) = ()
37

48
f ("", 1, true)
59
f[T1 = String] ("", 1, true)
@@ -12,5 +16,10 @@ object Test {
1216
f[T3 = Boolean, T2 = Int] ("", 1, true)
1317
f[T3 = Boolean, T1 = String] ("", 1, true)
1418
f[T1 = String, T2 = Int, T3 = Boolean]("", 1, true)
19+
f[T1 = String, T3 = Boolean, T2 = Int] ("", 1, true)
20+
f[T2 = Int, T1 = String, T3 = Boolean]("", 1, true)
21+
f[T2 = Int, T3 = Boolean, T1 = String] ("", 1, true)
22+
f[T3 = Boolean, T1 = String, T2 = Int] ("", 1, true)
23+
f[T3 = Boolean, T2 = Int, T1 = String] ("", 1, true)
1524
f[String, Int, Boolean] ("", 1, true)
1625
}

0 commit comments

Comments
 (0)