From f3276d6df65ddcb154520a00c52cfeea1efbc012 Mon Sep 17 00:00:00 2001 From: Miles Sabin Date: Tue, 26 Mar 2019 13:40:32 +0000 Subject: [PATCH 1/2] Pattern-bound type refs should have Case flag set Fixes #6157. --- .../src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 2 +- .../pos/inline-match-separate/inline-match-separate_1.scala | 6 ++++++ .../pos/inline-match-separate/inline-match-separate_2.scala | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/pos/inline-match-separate/inline-match-separate_1.scala create mode 100644 tests/pos/inline-match-separate/inline-match-separate_2.scala diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index ef22e72bc82d..8ac375029eff 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -513,7 +513,7 @@ class TreeUnpickler(reader: TastyReader, def complete(denot: SymDenotation)(implicit ctx: Context) = denot.info = typeReader.readType() } - val sym = ctx.newSymbol(ctx.owner, name, EmptyFlags, completer, coord = coordAt(start)) + val sym = ctx.newSymbol(ctx.owner, name, Flags.Case, completer, coord = coordAt(start)) registerSym(start, sym) sym } diff --git a/tests/pos/inline-match-separate/inline-match-separate_1.scala b/tests/pos/inline-match-separate/inline-match-separate_1.scala new file mode 100644 index 000000000000..667ac73edcfd --- /dev/null +++ b/tests/pos/inline-match-separate/inline-match-separate_1.scala @@ -0,0 +1,6 @@ +object Utils { + class Box[T] + inline def foo[T](t: T) <: Any = inline t match { + case _: Box[a] => scala.compiletime.constValue[a] + } +} diff --git a/tests/pos/inline-match-separate/inline-match-separate_2.scala b/tests/pos/inline-match-separate/inline-match-separate_2.scala new file mode 100644 index 000000000000..b2d43fceb3b1 --- /dev/null +++ b/tests/pos/inline-match-separate/inline-match-separate_2.scala @@ -0,0 +1,5 @@ +import Utils._ + +object Test { + val a = foo(new Box["a"]) +} From 07c4b8d8420a266549cb93baf32e2ea3d132da8f Mon Sep 17 00:00:00 2001 From: Miles Sabin Date: Wed, 27 Mar 2019 09:39:55 +0000 Subject: [PATCH 2/2] Added usage comment for Case --- compiler/src/dotty/tools/dotc/core/Flags.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 479b6753a09e..67dc4e6fe687 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -290,7 +290,9 @@ object Flags { final val PackageVal: FlagSet = Package.toTermFlags final val PackageClass: FlagSet = Package.toTypeFlags - /** A case class or its companion object */ + /** A case class or its companion object + * Note: Case is also used to indicate that a symbol is bound by a pattern. + */ final val Case: FlagSet = commonFlag(17, "case") final val CaseClass: FlagSet = Case.toTypeFlags final val CaseVal: FlagSet = Case.toTermFlags