Skip to content

Commit

Permalink
Backport "Allow SAM types to contain multiple refinements" to 3.3.4 (#…
Browse files Browse the repository at this point in the history
…21556)

Backports #20172 to Scala 3.3.4-RC2 as the follow-up to #20092
regression fix.

---------

Co-authored-by: Guillaume Martres <smarter@ubuntu.com>
Co-authored-by: Eugene Flesselle <eugene@flesselle.net>
  • Loading branch information
3 people authored Sep 6, 2024
1 parent 7b0a54b commit d69ae4e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5579,7 +5579,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)

Expand Down
7 changes: 7 additions & 0 deletions tests/run/i18315.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d69ae4e

Please sign in to comment.