lampepfl / dotty-feature-requests

Historical feature requests. Please create new feature requests at https://github.com/lampepfl/dotty/discussions/new?category=feature-requests
31 stars 2 forks source link

Give @targetName the ability to disambiguate SAM traits #291

Closed AugustNagro closed 2 years ago

AugustNagro commented 2 years ago

The @targetName annotation works great for this example:

@targetName("mapToInt")
def map(f: Int => Int): Int = ???
@targetName("mapToLong")
def map(f: Int => Long): Int = ???

But replacing the types with equivalent SAM traits does not compile with Ambiguous overload error:

trait ToInt { def apply(i: Int): Int }
trait ToLong { def apply(i: Int): Long }

@targetName("mapToInt")
def map(f: ToInt): Int = ???
@targetName("mapToLong")
def map(f: ToLong): Int = ???
AugustNagro commented 2 years ago

One reason this would be useful is for function specialization, since in Scala 3 the Function subclasses are not specialized, and box their parameters.

AugustNagro commented 2 years ago

Actually, function specialization is implemented now! my bad.