Skip to content

Constructor proxy permits only inserted apply #22841

Open
@som-snytt

Description

@som-snytt

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions