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

Constructor proxies break when "random" classes pop up on class path #22862

Open
som-snytt opened this issue Mar 23, 2025 · 2 comments
Open

Constructor proxies break when "random" classes pop up on class path #22862

som-snytt opened this issue Mar 23, 2025 · 2 comments
Labels
area:jdk Issues tied to artifacts published under a particular jdk compat:java itype:bug prio:low

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.6.4

Minimized code

class Compiler(c: Int)

@main def test = println:
  Compiler(42)

Output

  snips scala-cli compile --server=false -S 3.7.0-RC1 --jvm 17 no-compiler.scala

-- [E177] Reference Error: /home/amarki/snips/no-compiler.scala:5:2 ------------
5 |  Compiler(42)
  |  ^^^^^^^^
  |  Reference to constructor proxy for class Compiler
  |  shadows outer reference to object Compiler in package java.lang
  |
  |  The instance needs to be created with an explicit `new`.
  |
  | longer explanation available when compiling with `-explain`
1 error found
Compilation failed

Expectation

The API was deleted in modern JVMs, so this particular issue is resolved. However, we needn't be exposed to such brittleness.

-Yimports is too blunt an instrument.

It doesn't matter if I

import java.lang.{Compiler as _, *}

which is one of those clever Scala things which may or may not work. Maybe it would work for a Predef.

Maybe a directive could be used to unimport or shadow or otherwise specify a "profile" to compile against.

Noticed IRL at #17563 (comment)

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 23, 2025
@Gedochao Gedochao added compat:java and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 24, 2025
@Gedochao
Copy link
Contributor

The API was deleted in modern JVMs, so this particular issue is resolved.

This note is important, as it compiles fine on JVM > 17.

scala-cli compile repro.scala --jvm 18         
# Compiling project (Scala 3.6.3, JVM (18))
# Compiled project (Scala 3.6.3, JVM (18))

@Gedochao Gedochao added the area:jdk Issues tied to artifacts published under a particular jdk label Mar 24, 2025
@som-snytt
Copy link
Contributor Author

som-snytt commented Mar 24, 2025

Related to #17675 (was #17674)

Besides --release, there is no mechanism for hiding "API" in which we have no interest. The linked discussion is about how imports change meaning.

This ticket is about how a language feature suddenly "stops working". That is why I lodged it as a bug.

I adjusted the priority because it is a small nuisance, and maybe a head-scratcher, but not an impedance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:jdk Issues tied to artifacts published under a particular jdk compat:java itype:bug prio:low
Projects
None yet
Development

No branches or pull requests

2 participants