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

Add patch for undefined behavior with object $ #19705

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Feb 16, 2024

Add an ad-hoc patch to make it possible to use the broken object $ definitions in https://github.com/com-lihaoyi/Ammonite/blob/main/amm/interp/api/src/main/scala/ammonite/Stubs.scala.

This is a temporary patch while these definitions get deprecated. There is not guarantee that the semantics of these objects are correct. There is also no way to adapt the spec to allow there definition without breaking the language. For example consider object $ and object $$, how would we know if the $$.class is the class of $$ or the module class of $. We need to know this before we read the file.

Closes #19702

Add an ad-hoc patch to make it possible to use the broken `object $`
definitions in https://github.com/com-lihaoyi/Ammonite/blob/main/amm/interp/api/src/main/scala/ammonite/Stubs.scala.

This is a temporary patch while these definitions get deprecated. There
is not guarantee that the semantics of these objects are correct. There
is also no way to adapt the spec to allow there definition without breaking
the language. For example consider `object $` and `object $$`, how would
we know if the `$$.class` is the class of `$$` or the module class of `$`.
We need to know this before we read the file.
@nicolasstucki nicolasstucki marked this pull request as ready for review February 16, 2024 12:34
// Special case for `object $` in Amonite.
// This is an ad-hoc workaround for Amonite `object $`. See issue #19702
// This definition is not valid Scala.
&& classOrModuleName != "$"
Copy link
Member

Choose a reason for hiding this comment

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

so for clarity object $ makes $$.class, $.class, and $.tasty.
$$.class => $.tasty via standard code path
$.class => $.tasty via this escape hatch

@bishabosha bishabosha merged commit 898ce33 into scala:main Feb 19, 2024
19 checks passed
@bishabosha bishabosha deleted the patch-19702 branch February 19, 2024 15:22
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
lihaoyi pushed a commit to com-lihaoyi/Ammonite that referenced this pull request Jun 10, 2024
Added 3.4.2 to targets in a fairly straightforward, formulaic fashion.
3.4.0 and 3.4.1, for good reason, fail to parse `$` as a class file, but
a [temporary ad-hoc workaround was added in
3.4.2](scala/scala3#19705), so this needn't
block 3.4 support for now. Reliance on `object $` still needs to be
[fixed in
Ammonite](#1395).

Several internals changes required fixes also; I used the most obvious
solution (e.g. if Y extends X and Y is now private, use X instead), but
someone who knows more might want to read it over.

Tests pass on my machine for 3.3 and 3.4.2 (under Java 21).

If accepted, this patch would supersede
#1394
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.

Scala 3.4.0 can't load $ symbol classfile
3 participants