Skip to content

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

Open
@som-snytt

Description

@som-snytt

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions