File tree Expand file tree Collapse file tree 6 files changed +56
-7
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 6 files changed +56
-7
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,14 @@ object Inliner {
125125 case Apply (fn, args) =>
126126 cpy.Apply (tree)(liftBindings(fn, liftPos), args)
127127 case TypeApply (fn, args) =>
128+ fn.tpe.widenTermRefExpr match
129+ case tp : PolyType =>
130+ val targBounds = tp.instantiateParamInfos(args.map(_.tpe))
131+ for (arg, bounds : TypeBounds ) <- args.zip(targBounds) if ! bounds.contains(arg.tpe) do
132+ val boundsStr =
133+ if bounds == TypeBounds .empty then " <: Any. Note that this type is higher-kinded."
134+ else bounds.show
135+ report.error(em " ${arg.tpe} does not conform to bound $boundsStr" , arg)
128136 cpy.TypeApply (tree)(liftBindings(fn, liftPos), args)
129137 case Select (qual, name) =>
130138 cpy.Select (tree)(liftBindings(qual, liftPos), name)
Original file line number Diff line number Diff line change 1+ transparent inline def foo [T ]: Int = 10
2+
3+ def test =
4+ foo[List ] // error
Original file line number Diff line number Diff line change 1+ -- Error: tests/neg/i10552b.scala:10:17 --------------------------------------------------------------------------------
2+ 10 | println(foo1["hi"]) // error
3+ | ^^^^
4+ | ("hi" : String) does not conform to bound <: Int
5+ -- Error: tests/neg/i10552b.scala:11:17 --------------------------------------------------------------------------------
6+ 11 | println(foo1[String]) // error
7+ | ^^^^^^
8+ | String does not conform to bound <: Int
9+ -- Error: tests/neg/i10552b.scala:12:17 --------------------------------------------------------------------------------
10+ 12 | println(foo1[Any]) // error
11+ | ^^^
12+ | Any does not conform to bound <: Int
13+ -- Error: tests/neg/i10552b.scala:13:17 --------------------------------------------------------------------------------
14+ 13 | println(foo1[AnyKind]) // error
15+ | ^^^^^^^
16+ | AnyKind does not conform to bound <: Int
17+ -- Error: tests/neg/i10552b.scala:15:17 --------------------------------------------------------------------------------
18+ 15 | println(foo2["hi"]) // error
19+ | ^^^^
20+ | ("hi" : String) does not conform to bound >: Int <: Int
21+ -- Error: tests/neg/i10552b.scala:17:17 --------------------------------------------------------------------------------
22+ 17 | println(foo3[X]) // error
23+ | ^
24+ | Foo.this.X does not conform to bound <: Any. Note that this type is higher-kinded.
Original file line number Diff line number Diff line change 1+ class Foo :
2+ transparent inline def foo1 [A <: Int ]: Int = valueOf[A ]
3+ transparent inline def foo2 [A >: Int <: Int ]: Int = valueOf[A ]
4+ transparent inline def foo3 [A ]: Int = ???
5+
6+ type X >: AnyKind <: AnyKind
7+
8+ def run =
9+ println(foo1[Int ])
10+ println(foo1[" hi" ]) // error
11+ println(foo1[String ]) // error
12+ println(foo1[Any ]) // error
13+ println(foo1[AnyKind ]) // error
14+
15+ println(foo2[" hi" ]) // error
16+
17+ println(foo3[X ]) // error
Original file line number Diff line number Diff line change 11Some(true)
22Some(false)
3- Some(1)
4- Some(2)
53Some(3)
64Some(4)
75Some(5)
Original file line number Diff line number Diff line change 22@ main def Test : Unit =
33 testValueOfType[true ]
44 testValueOfType[false ]
5- testValueOfByte[1 ]
6- testValueOfShort[2 ]
5+ // TODO support Byte and short literal types
6+ // testValueOfType[1b]
7+ // testValueOfType[2s]
78 testValueOfType[3 ]
89 testValueOfType[4 ]
910 testValueOfType[5L ]
2930 testValueOfType[Null ]
3031 testValueOfType[Any ]
3132 testValueOfType[Some [1 ]]
32-
33- transparent inline def testValueOfByte [B <: Byte ] = testValueOfType[B ]
34- transparent inline def testValueOfShort [S <: Short ] = testValueOfType[S ]
You can’t perform that action at this time.
0 commit comments