From cff889be6fa8af83884b45cff90e3ec7f578673e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 30 Apr 2021 10:05:51 +0200 Subject: [PATCH] Don't use raw type ASTs in error message Fixes #12284 --- .../src/dotty/tools/dotc/core/Types.scala | 2 +- tests/neg/i12284.check | 41 +++++++++++++++++++ tests/neg/i12284.scala | 6 +++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i12284.check create mode 100644 tests/neg/i12284.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 8a0b0f12c167..3b0a76b59a6e 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -4432,7 +4432,7 @@ object Types { typr.println(msg) val bound = TypeComparer.fullUpperBound(origin) if !(atp <:< bound) then - throw new TypeError(s"$msg,\nbut the latter type does not conform to the upper bound $bound") + throw new TypeError(i"$msg,\nbut the latter type does not conform to the upper bound $bound") atp // AVOIDANCE TODO: This really works well only if variables are instantiated from below // If we hit a problematic symbol while instantiating from above, then avoidance diff --git a/tests/neg/i12284.check b/tests/neg/i12284.check new file mode 100644 index 000000000000..2f3adee6e948 --- /dev/null +++ b/tests/neg/i12284.check @@ -0,0 +1,41 @@ +-- Error: tests/neg/i12284.scala:5:36 ---------------------------------------------------------------------------------- +5 | val xx: Vector[F[_]] = deps.map(i => magic(i)) // error // error // error + | ^^^^^^^^^^^^^ + | return type B of lambda cannot be made hygienic; + | it is not a supertype of the hygienic type Any +-- Error: tests/neg/i12284.scala:5:33 ---------------------------------------------------------------------------------- +5 | val xx: Vector[F[_]] = deps.map(i => magic(i)) // error // error // error + | ^ + | Inaccessible variables captured in instantation of type variable B. + | F[i.A] was fixed to Any, + | but the latter type does not conform to the upper bound F[?] +-- Error: tests/neg/i12284.scala:5:6 ----------------------------------------------------------------------------------- +5 | val xx: Vector[F[_]] = deps.map(i => magic(i)) // error // error // error + | ^ + | Inaccessible variables captured in instantation of type variable B. + | F[i.A] was fixed to Any, + | but the latter type does not conform to the upper bound F[?] +-- Error: tests/neg/i12284.scala:4:2 ----------------------------------------------------------------------------------- +4 | val deps: Vector[I[F, _]] = ??? // error + | ^ + | Inaccessible variables captured in instantation of type variable B. + | F[i.A] was fixed to Any, + | but the latter type does not conform to the upper bound F[?] +-- Error: tests/neg/i12284.scala:3:4 ----------------------------------------------------------------------------------- +3 |def magic[F[_], A](in: I[F, A]): F[A] = // error // error + | ^ + | Inaccessible variables captured in instantation of type variable B. + | F[i.A] was fixed to Any, + | but the latter type does not conform to the upper bound F[?] +-- Error: tests/neg/i12284.scala:3:0 ----------------------------------------------------------------------------------- +3 |def magic[F[_], A](in: I[F, A]): F[A] = // error // error + |^ + |Inaccessible variables captured in instantation of type variable B. + |F[i.A] was fixed to Any, + |but the latter type does not conform to the upper bound F[?] +-- Error: tests/neg/i12284.scala:1:0 ----------------------------------------------------------------------------------- +1 |trait I[F[_], A] // error + |^ + |Inaccessible variables captured in instantation of type variable B. + |F[i.A] was fixed to Any, + |but the latter type does not conform to the upper bound F[?] diff --git a/tests/neg/i12284.scala b/tests/neg/i12284.scala new file mode 100644 index 000000000000..302ed6468f1f --- /dev/null +++ b/tests/neg/i12284.scala @@ -0,0 +1,6 @@ +trait I[F[_], A] // error + +def magic[F[_], A](in: I[F, A]): F[A] = // error // error + val deps: Vector[I[F, _]] = ??? // error + val xx: Vector[F[_]] = deps.map(i => magic(i)) // error // error // error + ??? \ No newline at end of file