From 07622a14108f77cbdf4356a9edfb1ec666392045 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Fri, 12 Apr 2024 11:12:58 +0200 Subject: [PATCH] Allow SAM types to contain multiple refinements --- compiler/src/dotty/tools/dotc/core/Types.scala | 2 +- tests/run/i18315.scala | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index ba48b6a0f2e6..47ba9833fc2f 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -5965,7 +5965,7 @@ object Types extends TypeUtils { def withRefinements(toType: Type, fromTp: Type): Type = fromTp.dealias match case RefinedType(fromParent, name, info: AliasingBounds) if tp0.member(name).exists => val parent1 = withRefinements(toType, fromParent) - RefinedType(toType, name, info) + RefinedType(parent1, name, info) case _ => toType val tp = withRefinements(tp0, origTp) diff --git a/tests/run/i18315.scala b/tests/run/i18315.scala index 85824920efbd..51a80420632d 100644 --- a/tests/run/i18315.scala +++ b/tests/run/i18315.scala @@ -7,9 +7,16 @@ trait Sam2: type T def apply(x: T): T +trait Sam3: + type T + type U + def apply(x: T): U + object Test: def main(args: Array[String]): Unit = val s1: Sam1 { type T = String } = x => x.trim s1.apply("foo") val s2: Sam2 { type T = Int } = x => x + 1 s2.apply(1) + val s3: Sam3 { type T = Int; type U = String } = x => x.toString + s3.apply(2)