Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Extension method is not shadowed by regular method #19435

som-snytt started this conversation in General Discussion
Discussion options

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
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /