File tree 3 files changed +20
-1
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -892,6 +892,23 @@ trait Applications extends Compatibility {
892
892
case _ =>
893
893
if originalProto.isDropped then fun1
894
894
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.
895
912
tree.args match {
896
913
case (arg @ Match (EmptyTree , cases)) :: Nil =>
897
914
typed(untpd.InlineMatch (EmptyTree , cases).withSpan(arg.span), pt)
Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ class Test {
38
38
case _ : Succ [n] => toIntT[n] + 1
39
39
}
40
40
41
+ inline def summonFrom (f : Nothing => Any ) <: Any = ???
42
+
41
43
final val two = toIntT[Succ [Succ [Zero .type ]]]
42
44
43
45
}
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ class Test extends App {
4
4
import scala .collection .immutable .{TreeSet , HashSet }
5
5
import scala .compiletime .summonFrom
6
6
7
- inline def setFor [T ] <: Set [T ] = compiletime. summonFrom {
7
+ inline def setFor [T ] <: Set [T ] = summonFrom {
8
8
case given ord : Ordering [T ] => new TreeSet [T ]
9
9
case _ => new HashSet [T ]
10
10
}
You can’t perform that action at this time.
0 commit comments