diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 7bad2b4a9fce..52d5991de176 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -125,6 +125,14 @@ object Inliner { case Apply(fn, args) => cpy.Apply(tree)(liftBindings(fn, liftPos), args) case TypeApply(fn, args) => + fn.tpe.widenTermRefExpr match + case tp: PolyType => + val targBounds = tp.instantiateParamInfos(args.map(_.tpe)) + for (arg, bounds: TypeBounds) <- args.zip(targBounds) if !bounds.contains(arg.tpe) do + val boundsStr = + if bounds == TypeBounds.empty then " <: Any. Note that this type is higher-kinded." + else bounds.show + report.error(em"${arg.tpe} does not conform to bound$boundsStr", arg) cpy.TypeApply(tree)(liftBindings(fn, liftPos), args) case Select(qual, name) => cpy.Select(tree)(liftBindings(qual, liftPos), name) diff --git a/tests/neg/i10552a.scala b/tests/neg/i10552a.scala new file mode 100644 index 000000000000..beae787609ad --- /dev/null +++ b/tests/neg/i10552a.scala @@ -0,0 +1,4 @@ +transparent inline def foo[T]: Int = 10 + +def test = + foo[List] // error diff --git a/tests/neg/i10552b.check b/tests/neg/i10552b.check new file mode 100644 index 000000000000..abaf55d2a947 --- /dev/null +++ b/tests/neg/i10552b.check @@ -0,0 +1,24 @@ +-- Error: tests/neg/i10552b.scala:10:17 -------------------------------------------------------------------------------- +10 | println(foo1["hi"]) // error + | ^^^^ + | ("hi" : String) does not conform to bound <: Int +-- Error: tests/neg/i10552b.scala:11:17 -------------------------------------------------------------------------------- +11 | println(foo1[String]) // error + | ^^^^^^ + | String does not conform to bound <: Int +-- Error: tests/neg/i10552b.scala:12:17 -------------------------------------------------------------------------------- +12 | println(foo1[Any]) // error + | ^^^ + | Any does not conform to bound <: Int +-- Error: tests/neg/i10552b.scala:13:17 -------------------------------------------------------------------------------- +13 | println(foo1[AnyKind]) // error + | ^^^^^^^ + | AnyKind does not conform to bound <: Int +-- Error: tests/neg/i10552b.scala:15:17 -------------------------------------------------------------------------------- +15 | println(foo2["hi"]) // error + | ^^^^ + | ("hi" : String) does not conform to bound >: Int <: Int +-- Error: tests/neg/i10552b.scala:17:17 -------------------------------------------------------------------------------- +17 | println(foo3[X]) // error + | ^ + | Foo.this.X does not conform to bound <: Any. Note that this type is higher-kinded. diff --git a/tests/neg/i10552b.scala b/tests/neg/i10552b.scala new file mode 100644 index 000000000000..58191c24645d --- /dev/null +++ b/tests/neg/i10552b.scala @@ -0,0 +1,17 @@ +class Foo: + transparent inline def foo1[A <: Int]: Int = valueOf[A] + transparent inline def foo2[A >: Int <: Int]: Int = valueOf[A] + transparent inline def foo3[A]: Int = ??? + + type X >: AnyKind <: AnyKind + + def run = + println(foo1[Int]) + println(foo1["hi"]) // error + println(foo1[String]) // error + println(foo1[Any]) // error + println(foo1[AnyKind]) // error + + println(foo2["hi"]) // error + + println(foo3[X]) // error diff --git a/tests/run-macros/from-type.check b/tests/run-macros/from-type.check index 9a5fe95f29aa..d8bff3300be2 100644 --- a/tests/run-macros/from-type.check +++ b/tests/run-macros/from-type.check @@ -1,7 +1,5 @@ Some(true) Some(false) -Some(1) -Some(2) Some(3) Some(4) Some(5) diff --git a/tests/run-macros/from-type/Test_2.scala b/tests/run-macros/from-type/Test_2.scala index 272ea7b5dac8..c14b164299f6 100644 --- a/tests/run-macros/from-type/Test_2.scala +++ b/tests/run-macros/from-type/Test_2.scala @@ -2,8 +2,9 @@ @main def Test: Unit = testValueOfType[true] testValueOfType[false] - testValueOfByte[1] - testValueOfShort[2] + // TODO support Byte and short literal types + // testValueOfType[1b] + // testValueOfType[2s] testValueOfType[3] testValueOfType[4] testValueOfType[5L] @@ -29,6 +30,3 @@ testValueOfType[Null] testValueOfType[Any] testValueOfType[Some[1]] - -transparent inline def testValueOfByte[B <: Byte] = testValueOfType[B] -transparent inline def testValueOfShort[S <: Short] = testValueOfType[S]