Skip to content

Make opaque type refinements of inline proxy objects abstract type constructors #20903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ class Inliner(val call: tpd.Tree)(using Context):
case _ =>
Nil
val refinements = openOpaqueAliases(cls.givenSelfType)
val refinedType = refinements.foldLeft(ref: Type) ((parent, refinement) =>
RefinedType(parent, refinement._1, TypeAlias(refinement._2))
)
val refinedType = refinements.foldLeft(ref: Type):
case (parent, (rname, ralias)) =>
RefinedType(parent, rname, RealTypeBounds(ralias, ralias))
val refiningSym = newSym(InlineBinderName.fresh(), Synthetic, refinedType).asTerm
val refiningDef = ValDef(refiningSym, tpd.ref(ref).cast(refinedType), inferred = true).withSpan(span)
inlining.println(i"add opaque alias proxy $refiningDef for $ref in $tp")
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ mt-redux-norm.perspective.scala
i18211.scala
10867.scala
named-tuples1.scala
inline-match-opaque.scala

# Opaque type
i5720.scala
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/inline-match-opaque-2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.language.experimental.namedTuples

object Test:
type NT = NamedTuple.Concat[(hi: Int), (bla: String)]
def foo(x: NT) =
x.hi // error
19 changes: 19 additions & 0 deletions tests/pos/inline-match-opaque.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
object Foo:
opaque type Wrapper[T] = T
def part[T](w: Wrapper[T]): T = w
inline def part2[T](w: Wrapper[T]): T = part(w) //part(w.asInstanceOf[Wrapper[T]]) also fixes the issue
type Rewrap[W] = Wrapper[Extra.Unwrap[W]]

object Extra:
type Unwrap[W] = W match
case Foo.Wrapper[t] => t
type Rewrap[W] = Foo.Wrapper[Unwrap[W]]

object Test:
type X = Extra.Rewrap[Foo.Wrapper[Int]]
def foo1(x: Foo.Wrapper[Extra.Unwrap[Foo.Wrapper[Int]]]) =
Foo.part(x) // ok
Foo.part2(x) // ok
def foo2(x: X) =
Foo.part(x) // ok
Foo.part2(x) // error
Loading