From 685d292a9b213634491d72e3851a23e59da7dd6d 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 [Cherry-picked c35a7001de53bcb624a27bbd36a3724a3ac90d81] --- 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 a0913b628abd..ee1c9ce17226 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -407,7 +407,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 aa0a9042d779a4ccfbc048718609a8aabe793c64 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 [Cherry-picked 01a37ec68d9f745eb4be412364f8dbf655fc454f] --- 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 ee1c9ce17226..89c0fcfc146c 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -407,7 +407,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