Skip to content

Commit 7c095ae

Browse files
Fix 12974: Add test case
1 parent d268725 commit 7c095ae

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/neg/12974.scala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package example
2+
3+
object RecMap {
4+
5+
object Record {
6+
// use this scope to bound who can see inside the opaque type
7+
opaque type Rec[A <: Tuple] = Map[String, Any]
8+
9+
object Rec {
10+
type HasKey[A <: Tuple, K] =
11+
A match
12+
case (K, t) *: _ => t
13+
case _ *: t => HasKey[t, K]
14+
15+
val empty: Rec[EmptyTuple] = Map.empty
16+
17+
extension [A <: Tuple](toMap: Rec[A])
18+
def fetch[K <: String & Singleton](key: K): HasKey[A, K] =
19+
toMap(key).asInstanceOf[HasKey[A, K]]
20+
}
21+
}
22+
23+
def main(args: Array[String]) =
24+
import Record._
25+
26+
val foo: Any = Rec.empty.fetch("foo") // error
27+
// ^
28+
// Match type reduction failed since selector EmptyTuple.type
29+
// matches none of the cases
30+
//
31+
// case (("foo" : String), t) *: _ => t
32+
// case _ *: t => example.RecMap.Record.Rec.HasKey[t, ("foo" : String)]
33+
34+
end main
35+
}

0 commit comments

Comments
 (0)