-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Extension method is not shadowed by regular method #19435
som-snytt
started this conversation in
General Discussion
-
I was surprised that the extension is not shadowed:
object Test:
extension (i: Int) def ok(j: Int) = i+j
def test = 42.ok(27)
class C:
def ok(i: Int)(j: Int) = i*j
def c = 42.ok(27)
def f = ok(42)(27)
@main def main() = println:
val x = Test.C()
(x.c, x.f)
The reference language is "available as a simple name", as in Scala 2, and def g = ok
in Scala 3 means the local ok
and not the extension.
Noticed at https://discord.com/channels/632150470000902164/632628489719382036/1195117929155530792 where my surprise was that braces in REPL 3 do not mean locally
. As shown, the extension becomes an imported member for res1
which is not shadowed.
scala> { extension (i: Int) def ok(j: Int) = i+j ; 42.ok(27) }
def ok(i: Int)(j: Int): Int
val res0: Int = 69
scala> { def ok(i: Int)(j: Int) = i+j ; 42.ok(27) }
def ok(i: Int)(j: Int): Int
val res1: Int = 69
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment