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 proxy permits only inserted apply #22841

Open
som-snytt opened this issue Mar 19, 2025 · 0 comments
Open

Constructor proxy permits only inserted apply #22841

som-snytt opened this issue Mar 19, 2025 · 0 comments

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.6.4

Minimized code

Welcome to Scala 3.6.4 (23.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> class C { def f(s: String) = 42 }
// defined class C

scala> C().f("s")
val res0: Int = 42

scala> class C { def apply(s: String) = 42 }
// defined class C

scala> C()("s")
val res1: Int = 42

scala> C().apply("s")
-- [E050] Type Error: ----------------------------------------------------------
1 |C().apply("s")
  |^
  |object C does not take parameters
  |
  | longer explanation available when compiling with `-explain`
1 error found

scala>

Expectation

Constructor proxy syntax understands that I might want to call apply on my instance.

Should I use subjunctive here? "That it understand my intentions."

Noticed during rewrite of C()() where apply takes implicits. The erroneous application should be C().apply.

Same problem with using:

Welcome to Scala 3.7.0-RC1 (23.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> class C { def apply(using String) = 42 }
// defined class C

scala> given String = "hello, world"
lazy val given_String: String

scala> C().apply
-- [E050] Type Error: ----------------------------------------------------------
1 |C().apply
  |^
  |object C does not take parameters
  |
  | longer explanation available when compiling with `-explain`
1 error found
@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 19, 2025
@Gedochao Gedochao added area:constructors and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants