File tree 6 files changed +56
-7
lines changed
compiler/src/dotty/tools/dotc/typer
6 files changed +56
-7
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,14 @@ object Inliner {
125
125
case Apply (fn, args) =>
126
126
cpy.Apply (tree)(liftBindings(fn, liftPos), args)
127
127
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)
128
136
cpy.TypeApply (tree)(liftBindings(fn, liftPos), args)
129
137
case Select (qual, name) =>
130
138
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 1
1
Some(true)
2
2
Some(false)
3
- Some(1)
4
- Some(2)
5
3
Some(3)
6
4
Some(4)
7
5
Some(5)
Original file line number Diff line number Diff line change 2
2
@ main def Test : Unit =
3
3
testValueOfType[true ]
4
4
testValueOfType[false ]
5
- testValueOfByte[1 ]
6
- testValueOfShort[2 ]
5
+ // TODO support Byte and short literal types
6
+ // testValueOfType[1b]
7
+ // testValueOfType[2s]
7
8
testValueOfType[3 ]
8
9
testValueOfType[4 ]
9
10
testValueOfType[5L ]
29
30
testValueOfType[Null ]
30
31
testValueOfType[Any ]
31
32
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