Skip to content

Commit 2b8ba68

Browse files
committed
Fix test
1 parent 2b25407 commit 2b8ba68

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,23 @@ trait Applications extends Compatibility {
892892
case _ =>
893893
if originalProto.isDropped then fun1
894894
else if fun1.symbol == defn.Compiletime_summonFrom then
895+
// Special handling of `summonFrom { ... }`.
896+
// We currently cannot use a macro for that since unlike other inline methods
897+
// summonFrom needs to expand lazily. For instance, in
898+
//
899+
// summonFrom {
900+
// case given A[t] =>
901+
// summonFrom
902+
// case given `t` => ...
903+
// }
904+
// }
905+
//
906+
// the second `summonFrom` should expand only once the first `summonFrom` is
907+
// evaluated and `t` is bound. But normal inline expansion does not behave that
908+
// way: arguments to inline function are expanded before the function call.
909+
// To make this work using regular inlining, we'd need a way to annotate
910+
// an inline function that it should expand only if there are no enclosing
911+
// applications of inline functions.
895912
tree.args match {
896913
case (arg @ Match(EmptyTree, cases)) :: Nil =>
897914
typed(untpd.InlineMatch(EmptyTree, cases).withSpan(arg.span), pt)

tests/pos/reference/compile-time.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class Test {
3838
case _: Succ[n] => toIntT[n] + 1
3939
}
4040

41+
inline def summonFrom(f: Nothing => Any) <: Any = ???
42+
4143
final val two = toIntT[Succ[Succ[Zero.type]]]
4244

4345
}

tests/pos/reference/delegate-match.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Test extends App {
44
import scala.collection.immutable.{TreeSet, HashSet}
55
import scala.compiletime.summonFrom
66

7-
inline def setFor[T] <: Set[T] = compiletime.summonFrom {
7+
inline def setFor[T] <: Set[T] = summonFrom {
88
case given ord: Ordering[T] => new TreeSet[T]
99
case _ => new HashSet[T]
1010
}

0 commit comments

Comments
 (0)