Skip to content

Commit 1516b06

Browse files
Merge pull request #8756 from dotty-staging/use-transparent-inline-in-the-library
Use transparent inline in the library
2 parents c560211 + 417c39d commit 1516b06

File tree

28 files changed

+43
-41
lines changed

28 files changed

+43
-41
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,6 +3288,7 @@ object Parsers {
32883288
leadingVparamss ::: rparamss
32893289
var tpt = fromWithinReturnType {
32903290
if in.token == SUBTYPE && mods.is(Inline) && AllowOldWhiteboxSyntax then
3291+
deprecationWarning("`<:` return type will no longer be supported. Use transparent modifier instead.")
32913292
in.nextToken()
32923293
mods1 = addMod(mods1, Mod.Transparent())
32933294
toplevelTyp()
@@ -3557,6 +3558,7 @@ object Parsers {
35573558
mods1 |= Final
35583559
DefDef(name, tparams, vparamss, tpt, subExpr())
35593560
if in.token == USCORE && AllowOldWhiteboxSyntax then
3561+
deprecationWarning("`<:` return type will no longer be supported. Use transparent modifier instead.")
35603562
if !mods.is(Inline) then
35613563
syntaxError("`_ <:` is only allowed for given with `inline` modifier")
35623564
in.nextToken()

library/src/dotty/DottyPredef.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object DottyPredef {
88
assertFail(message)
99
}
1010

11-
inline final def assert(inline assertion: Boolean) <: Unit = {
11+
transparent inline final def assert(inline assertion: Boolean): Unit = {
1212
if (!assertion)
1313
assertFail()
1414
}

library/src/scala/compiletime/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ package object compiletime {
5252
*
5353
* the returned value would be `2`.
5454
*/
55-
inline def summonFrom[T](f: Nothing => T) <: T = ???
55+
transparent inline def summonFrom[T](f: Nothing => T): T = ???
5656

5757

5858
/** Summon a given value of type `T`. Usually, the argument is not passed explicitly.
@@ -61,7 +61,7 @@ package object compiletime {
6161
* @tparam T the type of the value to be summoned
6262
* @return the given value typed as the provided type parameter
6363
*/
64-
inline def summonInline[T] <: T = summonFrom {
64+
transparent inline def summonInline[T]: T = summonFrom {
6565
case t: T => t
6666
}
6767

tests/invalid/run/typelevel-patmat.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object Test extends App {
4545
inline val i2 = toInt(y2)
4646
val j2: 2 = i2
4747

48-
inline def concat(xs: HList, ys: HList) <: HList = inline xs match {
48+
transparent inline def concat(xs: HList, ys: HList): HList = inline xs match {
4949
case HNil => ys
5050
case HCons(x, xs1) => HCons(x, concat(xs1, ys))
5151
}
@@ -68,7 +68,7 @@ object Test extends App {
6868
val r6 = concat(HCons(1, HCons("a", HNil)), HCons(true, HCons(1.0, HNil)))
6969
val c6: HCons[Int, HCons[String, HCons[Boolean, HCons[Double, HNil]]]] = r6
7070

71-
inline def nth(xs: HList, n: Int) <: Any = inline xs match {
71+
transparent inline def nth(xs: HList, n: Int): Any = inline xs match {
7272
case HCons(x, _) if n == 0 => x
7373
case HCons(_, xs1) if n > 0 => nth(xs1, n - 1)
7474
}

tests/invalid/run/typelevel1.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ trait HList {
44
def head: Any
55
def tail: HList
66

7-
inline def isEmpty <: Boolean = length == 0
7+
transparent inline def isEmpty: Boolean = length == 0
88
}
99

1010
case object HNil extends HList {
11-
inline override def length <: Int = 0
11+
transparent inline override def length: Int = 0
1212
def head: Nothing = ???
1313
def tail: Nothing = ???
1414
}
1515

1616
case class :: [H, T <: HList] (hd: H, tl: T) extends HList {
17-
inline override def length <: Int = 1 + tl.length
17+
transparent inline override def length: Int = 1 + tl.length
1818
inline def head: H = this.hd
1919
inline def tail: T = this.tl
2020
}
@@ -32,7 +32,7 @@ object Test extends App {
3232

3333
// Does not work since it infers `Any` as a type argument for `::`
3434
// and we cannot undo that without a typing from untyped.
35-
inline def concat[T1, T2](xs: HList, ys: HList) <: HList =
35+
transparent inline def concat[T1, T2](xs: HList, ys: HList): HList =
3636
inline if xs.isEmpty then ys
3737
else new ::(xs.head, concat(xs.tail, ys))
3838

tests/neg-macros/quote-whitebox/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.quoted._
22

33
object Macros {
4-
inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl('str) }
4+
transparent inline def defaultOf(inline str: String): Any = ${ defaultOfImpl('str) }
55
def defaultOfImpl(str: Expr[String]) (using QuoteContext): Expr[Any] = str.unliftOrError match {
66
case "int" => '{1}
77
case "string" => '{"a"}

tests/neg/specializing-inline.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object Test {
44
val z = h(true)
55
val zc: Int = z // error
66

7-
inline def g <: Any = 1
7+
transparent inline def g: Any = 1
88
val y = g
99
val yc: Int = y // OK
1010

tests/pending/pos/summonFrom.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object summonFroms {
44
object invariant {
55
case class Box[T](value: T)
66
implicit val box: Box[Int] = Box(0)
7-
inline def unbox <: Any = summonInline[Box[t]].value
7+
transparent inline def unbox: Any = summonInline[Box[t]].value
88
val i: Int = unbox
99
val i2 = unbox
1010
val i3: Int = i2
@@ -13,7 +13,7 @@ object summonFroms {
1313
object covariant {
1414
case class Box[+T](value: T)
1515
implicit val box: Box[Int] = Box(0)
16-
inline def unbox <: Any = summonInline[Box[t]].value
16+
transparent inline def unbox: Any = summonInline[Box[t]].value
1717
val i: Int = unbox
1818
val i2 = unbox
1919
val i3: Int = i2
@@ -22,7 +22,7 @@ object summonFroms {
2222
object contravariant {
2323
case class TrashCan[-T](trash: T => Unit)
2424
implicit val trashCan: TrashCan[Int] = TrashCan { i => ; }
25-
inline def trash <: Nothing => Unit = summonInline[TrashCan[t]].trash
25+
transparent inline def trash: Nothing => Unit = summonInline[TrashCan[t]].trash
2626
val t1: Int => Unit = trash
2727
val t2 = trash
2828
val t3: Int => Unit = t2

tests/pos-macros/quote-whitebox-2/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.quoted._
33

44
object Macro {
55

6-
inline def charOrString(inline str: String) <: Any = ${ impl('str) }
6+
transparent inline def charOrString(inline str: String): Any = ${ impl('str) }
77

88
def impl(strExpr: Expr[String]) (using QuoteContext)=
99
val str = strExpr.unliftOrError

tests/pos/given-pattern.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Test {
44
import scala.collection.immutable.{TreeSet, HashSet}
55

6-
inline def trySummon[S, T](f: PartialFunction[S, T]) <: T = ???
6+
transparent inline def trySummon[S, T](f: PartialFunction[S, T]): T = ???
77

88
inline def setFor[T]: Set[T] = trySummon {
99
case given ord: Ordering[T] => new TreeSet[T]

0 commit comments

Comments
 (0)