From c35a7001de53bcb624a27bbd36a3724a3ac90d81 Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Tue, 14 Nov 2023 16:43:56 +0100 Subject: [PATCH 1/2] Fix condition in prefixIsElidable to prevent compiler crash --- compiler/src/dotty/tools/dotc/ast/tpd.scala | 2 +- tests/pos/i18091.scala | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i18091.scala diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index acffb1e89972..b1ba569445a3 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -414,7 +414,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { case pre: ThisType => tp.isType || pre.cls.isStaticOwner || - tp.symbol.isParamOrAccessor && !pre.cls.is(Trait) && ctx.owner.enclosingClass == pre.cls + tp.symbol.isParamOrAccessor && !tp.symbol.owner.is(Trait) && ctx.owner.enclosingClass == pre.cls // was ctx.owner.enclosingClass.derivesFrom(pre.cls) which was not tight enough // and was spuriously triggered in case inner class would inherit from outer one // eg anonymous TypeMap inside TypeMap.andThen diff --git a/tests/pos/i18091.scala b/tests/pos/i18091.scala new file mode 100644 index 000000000000..ef896cedb751 --- /dev/null +++ b/tests/pos/i18091.scala @@ -0,0 +1,5 @@ +trait B(val y: Int) + +class C extends B(20) { + def foo(): Unit = println(y) +} \ No newline at end of file From 01a37ec68d9f745eb4be412364f8dbf655fc454f Mon Sep 17 00:00:00 2001 From: Szymon Rodziewicz Date: Tue, 14 Nov 2023 18:54:26 +0100 Subject: [PATCH 2/2] Keep the previous condition in preflixElidable --- compiler/src/dotty/tools/dotc/ast/tpd.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index b1ba569445a3..6f54f342dcb2 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -414,7 +414,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { case pre: ThisType => tp.isType || pre.cls.isStaticOwner || - tp.symbol.isParamOrAccessor && !tp.symbol.owner.is(Trait) && ctx.owner.enclosingClass == pre.cls + tp.symbol.isParamOrAccessor && !pre.cls.is(Trait) && !tp.symbol.owner.is(Trait) && ctx.owner.enclosingClass == pre.cls // was ctx.owner.enclosingClass.derivesFrom(pre.cls) which was not tight enough // and was spuriously triggered in case inner class would inherit from outer one // eg anonymous TypeMap inside TypeMap.andThen