forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request scala#8822 from dotty-staging/fix-#8736
Fix scala#8736: Handle alternatives with same signature in overloading resolution
- Loading branch information
Showing
6 changed files
with
82 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/i8736.scala:29:29 ------------------------------------------------------------- | ||
29 | def res1: String = rec.get("k") // error: type mismatch | ||
| ^^^^^^^^^^^^ | ||
| Found: Any | ||
| Required: String | ||
-- [E007] Type Mismatch Error: tests/neg/i8736.scala:30:29 ------------------------------------------------------------- | ||
30 | def res2: Int = rec.get("v") // error: type mismatch | ||
| ^^^^^^^^^^^^ | ||
| Found: Any | ||
| Required: Int | ||
-- [E051] Reference Error: tests/neg/i8736.scala:31:26 ----------------------------------------------------------------- | ||
31 | def res3: Boolean = rec.get("z") // error: ambiguous | ||
| ^^^^^^^ | ||
| Ambiguous overload. The overloaded alternatives of method (k: ("k" : String)): String with types | ||
| (k: ("k" : String)): String | ||
| (k: ("v" : String)): Int | ||
| (k: ("z" : String)): Boolean | ||
| all match arguments (("z" : String)) | ||
| | ||
| Note: this happens because two or more alternatives have the same erasure, | ||
| so they cannot be distinguished by overloading resolution | ||
|
||
longer explanation available when compiling with `-explain` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import reflect.Selectable.reflectiveSelectable | ||
object App extends App { | ||
|
||
trait Rec0[K <: String] { | ||
private[App] val map: Map[String, Any] | ||
def get(k: K): Any | ||
} | ||
def Rec0(map0: Map[String, Any]) = new Rec0[String] { | ||
val map = map0 | ||
def get(k: String): Any = map(k) | ||
} | ||
|
||
type Rec[K <: String, V0] = Rec0[K] { def get(k: K): V0 } | ||
def field[V](s: String)(v: V): Rec[s.type, V] = Rec0(Map(s -> v)).asInstanceOf[Rec[s.type, V]] | ||
|
||
implicit class RecOps[R <: Rec0[_]](has: R) { | ||
def +[K1 <: String, V1](that: Rec[K1, V1]): R with Rec[K1, V1] = Rec0(has.map ++ that.map).asInstanceOf[R with Rec[K1, V1]] | ||
} | ||
|
||
def rec: | ||
Rec["k", String] | ||
with Rec["v", Int] | ||
with Rec["z", Boolean] | ||
= { | ||
field("k")("Str") + | ||
field("v")(0) + | ||
field("z")(true) | ||
} | ||
def res1: String = rec.get("k") // error: type mismatch | ||
def res2: Int = rec.get("v") // error: type mismatch | ||
def res3: Boolean = rec.get("z") // error: ambiguous | ||
|
||
// def res4: Boolean = rec.get("nofield") | ||
|
||
println((res1, res2, res3)) | ||
} |