@@ -29,8 +29,6 @@ trait AsyncTransform {
29
29
DefDef (NoMods , name.apply, Nil , applyVParamss, TypeTree (definitions.UnitTpe ), Literal (Constant (())))
30
30
}
31
31
32
- val stateMachineType = applied(" scala.async.StateMachine" , List (futureSystemOps.promType[T ](uncheckedBoundsResultTag), futureSystemOps.execContextType))
33
-
34
32
// Create `ClassDef` of state machine with empty method bodies for `resume` and `apply`.
35
33
val stateMachine : ClassDef = {
36
34
val body : List [Tree ] = {
@@ -43,10 +41,15 @@ trait AsyncTransform {
43
41
// See SI-1247 for the the optimization that avoids creatio
44
42
DefDef (NoMods , name.apply, Nil , Nil , TypeTree (definitions.UnitTpe ), Apply (Ident (name.resume), Nil ))
45
43
}
46
- List (emptyConstructor, stateVar, result, execContextValDef) ++ List (resumeFunTreeDummyBody, applyDefDefDummyBody, apply0DefDef)
44
+ val extraValDef : ValDef = {
45
+ // We extend () => Unit so we can pass this class as the by-name argument to `Future.apply`.
46
+ // See SI-1247 for the the optimization that avoids creatio
47
+ ValDef (NoMods , newTermName(" extra" ), TypeTree (definitions.UnitTpe ), Literal (Constant (())))
48
+ }
49
+ List (emptyConstructor, stateVar, result, execContextValDef) ++ List (resumeFunTreeDummyBody, applyDefDefDummyBody, apply0DefDef, extraValDef)
47
50
}
48
51
49
- val template = Template (List (stateMachineType ), emptyValDef, body)
52
+ val template = Template (List (typeOf[(scala.util. Try [ Any ] => Unit )], typeOf[() => Unit ]).map( TypeTree (_) ), emptyValDef, body)
50
53
51
54
val t = ClassDef (NoMods , name.stateMachineT, Nil , template)
52
55
callSiteTyper.typedPos(macroPos)(Block (t :: Nil , Literal (Constant (()))))
@@ -93,7 +96,7 @@ trait AsyncTransform {
93
96
94
97
Block (List [Tree ](
95
98
stateMachineSpliced,
96
- ValDef (NoMods , name.stateMachine, stateMachineType , Apply (Select (New (Ident (stateMachine.symbol)), nme.CONSTRUCTOR ), Nil )),
99
+ ValDef (NoMods , name.stateMachine, TypeTree () , Apply (Select (New (Ident (stateMachine.symbol)), nme.CONSTRUCTOR ), Nil )),
97
100
futureSystemOps.spawn(Apply (selectStateMachine(name.apply), Nil ), selectStateMachine(name.execContext))
98
101
),
99
102
futureSystemOps.promiseToFuture(Expr [futureSystem.Prom [T ]](selectStateMachine(name.result))).tree)
0 commit comments