Skip to content
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

Heal member-select on opaque reference #19730

Merged
merged 3 commits into from
Jun 12, 2024
Merged

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Feb 19, 2024

When the prefix of an opaque isn't the .this reference of the module
class, then its RHS isn't visible. TypeComparer uses ctx.owner to
"heal" or "lift" this type such that it is. We reuse that logic for
member selection.

Fixes #19609

@dwijnand dwijnand marked this pull request as ready for review February 23, 2024 10:09
@dwijnand dwijnand requested a review from sjrd February 23, 2024 10:10
Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

My only real comment is to consider putting all the branches in separate defs. The rest is mostly rambling as I tried to understand the thing.

compiler/src/dotty/tools/dotc/typer/Typer.scala Outdated Show resolved Hide resolved
compiler/src/dotty/tools/dotc/typer/Typer.scala Outdated Show resolved Hide resolved
@sjrd sjrd assigned dwijnand and unassigned sjrd Feb 27, 2024
@dwijnand dwijnand force-pushed the select-opaque branch 2 times, most recently from f9025c9 to 6847de0 Compare March 4, 2024 13:11
@dwijnand dwijnand assigned sjrd and unassigned dwijnand Mar 4, 2024
@dwijnand dwijnand requested a review from sjrd March 4, 2024 22:28
@som-snytt
Copy link
Contributor

@dwijnand also fixes example 1 in #15050

import OpaqueBug.*
def g(n: Counter): Counter = n
object OpaqueBug:
  opaque type Counter = Int
  val initial: Counter = 42
  def f(n: Int): Int = g(n) + initial

@main def run = println(OpaqueBug.f(21))

@dwijnand dwijnand force-pushed the select-opaque branch 2 times, most recently from a9f23c1 to 5a4d891 Compare June 11, 2024 13:49
dwijnand added 3 commits June 12, 2024 10:12
Prior to the next commit, I broke up the logic into internal methods, so
some can be reused, consuming then in a big Tree#orElse chain.  I also
took the opportunity to rename the method, to more easily distinguish it
from the other typedSelect.
When the prefix of an opaque isn't the .this reference of the module
class, then its RHS isn't visible.  TypeComparer uses ctx.owner to
"heal" or "lift" this type such that it is.  We reuse that logic for
member selection.
@dwijnand dwijnand merged commit 82ac0dd into scala:main Jun 12, 2024
24 checks passed
@dwijnand dwijnand deleted the select-opaque branch June 12, 2024 12:00
@Kordyjan Kordyjan added this to the 3.5.1 milestone Jul 3, 2024
WojciechMazur added a commit that referenced this pull request Jul 9, 2024
Backports #19730 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
WojciechMazur added a commit that referenced this pull request Aug 8, 2024
This reverts commit 4443395.

This reverts the behaviour changing part of #19730, which could make
code that previously compiled, continue to
compile but with a different runtime behaviour. Now, the code in
question is very niche and esoteric, and
effectively exploiting this opaque typing bug. So, we're happy to change
the compiler to make this behaviour
silently change, just not in a patch release.
WojciechMazur added a commit that referenced this pull request Aug 8, 2024
This reverts commit 4443395.

This reverts the behaviour changing part of #19730, which could make
code that previously compiled, continue to
compile but with a different runtime behaviour. Now, the code in
question is very niche and esoteric, and
effectively exploiting this opaque typing bug. So, we're happy to change
the compiler to make this behaviour
silently change, just not in a patch release.

(Same as #21340, but for the LTS.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opaque type not transparent in its defining scope, when referred to via qualified name
4 participants