C# Language Proposal discussion: Target-typed static member lookup

There’s been some discussion around adopting Swift-like .member shorthand syntax in Scala, to avoid having to use the full Object.member syntax based on target-typing. As another data point, apart from Swift, C# seems like it might be getting this in the near future:

3 Likes

Why not continue on that thread?

1 Like

Because I couldnt find it haha, if any mods could help consolidate this thread into the other one that would be great

I actually made a similar proposal not long ago where I proposed to use a placeholder for the companion object (I suggested # at the time to avoid clashes with existing syntax, but the specific syntax isn’t important to me), with scoping rules analogous to those that we use for _ placeholders in lambda expressions. Then you could just write #.member. But it’s more powerful than a simple .member syntax because it can be used also in situations where you don’t want to access a member. For example, you could write something like

def fun(ints: Vector[Int]) = ???

val ints = List(1,2,3)
fun(ints.to(#)) // compiler figures out which collection type to convert to

Unfortunately Martin didn’t like it, saying it’s too prone to misuse for unreadable code.