Skip to content

Defend against AliasingBounds #23668

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,9 @@ object RefChecks {
def targetOfHiddenExtension: Symbol =
val target =
val target0 = explicitInfo.firstParamTypes.head // required for extension method, the putative receiver
target0.dealiasKeepOpaques.typeSymbol.info
target0.dealiasKeepOpaques.typeSymbol.info match
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of weird since dealias does skip aliasing bounds. It would be good to get an explanation what exactly goes wrong here. What's the type of target0.dealiasKeepOpaques in the failing test? What is its info? Is there an opaque type involved?

case tb: AliasingBounds => tb.alias
case tp => tp
val member = target.nonPrivateMember(sym.name)
.filterWithPredicate: member =>
member.symbol.isPublic && memberHidesMethod(member)
Expand Down
14 changes: 14 additions & 0 deletions tests/pos/i23666.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

type Tuple = scala.Tuple
type Any = scala.Any

infix type =:= [A, B] = A => B

object `=:=` :
given [A] => A =:= A = a => a

extension [T <: Tuple] (tuple: T)

def reverse[A, B](using ev: T =:= (A, B)): (B, A) =
val ab = ev(tuple)
(ab._2, ab._1)
Loading