diff --git a/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala b/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala index 6bbf253d3b80..a3c1484d4e62 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala @@ -4,7 +4,7 @@ package ast import core._ import Types._, Contexts._ -import Symbols._, Annotations._, Trees._, Symbols._ +import Symbols._, Annotations._, Trees._, Symbols._, Constants.Constant import Decorators._ import dotty.tools.dotc.transform.SymUtils._ import core.tasty.TreePickler.Hole @@ -124,6 +124,8 @@ class TreeTypeMap( cpy.Labeled(labeled)(bind1, expr1) case Hole(isTermHole, n, args) => Hole(isTermHole, n, args.mapConserve(transform)).withSpan(tree.span).withType(mapType(tree.tpe)) + case lit @ Literal(Constant(tpe: Type)) => + cpy.Literal(lit)(Constant(mapType(tpe))) case tree1 => super.transform(tree1) } diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index a9baa4d65802..b1939261084f 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -835,8 +835,10 @@ object Symbols { info = completer, privateWithin = ttmap1.mapOwner(odenot.privateWithin), // since this refers to outer symbols, need not include copies (from->to) in ownermap here. annotations = odenot.annotations) - copy.registeredCompanion = - copy.registeredCompanion.subst(originals, copies) + copy.denot match + case cd: ClassDenotation => + cd.registeredCompanion = cd.unforcedRegisteredCompanion.subst(originals, copies) + case _ => } copies.foreach(_.ensureCompleted()) // avoid memory leak diff --git a/tests/pos/i10542.scala b/tests/pos/i10542.scala new file mode 100644 index 000000000000..f6c759ef4769 --- /dev/null +++ b/tests/pos/i10542.scala @@ -0,0 +1,38 @@ +package test_10542: + + trait Foo { + inline def foo[A](t: => A): Unit = () + } + + object Bar extends Foo + + object Test { + Bar.foo { + sealed trait T1 + case object S1 extends T1 + } + } + +package test_10540: + + trait Foo { + inline def foo[A](t: => A): Unit = () + } + + object Bar extends Foo + + object Test { + Bar.foo { + trait T1 + val array = Array(new T1 {}) + } + } + +package test_9655: + + inline def foo[T](inline body: T): T = body + + def test = foo { + sealed trait Status + object Active extends Status + }