@@ -136,7 +136,7 @@ abstract class GenJSCode extends plugins.PluginComponent
136
136
137
137
// Per method body
138
138
private val currentMethodSym = new ScopedVar [Symbol ]
139
- private val thisLocalVarIdent = new ScopedVar [Option [js.Ident ]]
139
+ private val thisLocalVarInfo = new ScopedVar [Option [( js.Ident , jstpe. Type ) ]]
140
140
private val fakeTailJumpParamRepl = new ScopedVar [(Symbol , Symbol )]
141
141
private val enclosingLabelDefParams = new ScopedVar [Map [Symbol , List [Symbol ]]]
142
142
private val isModuleInitialized = new ScopedVar [VarBox [Boolean ]]
@@ -168,7 +168,7 @@ abstract class GenJSCode extends plugins.PluginComponent
168
168
unexpectedMutatedFields := mutable.Set .empty,
169
169
generatedSAMWrapperCount := null ,
170
170
currentMethodSym := null ,
171
- thisLocalVarIdent := null ,
171
+ thisLocalVarInfo := null ,
172
172
fakeTailJumpParamRepl := null ,
173
173
enclosingLabelDefParams := null ,
174
174
isModuleInitialized := null ,
@@ -1397,7 +1397,7 @@ abstract class GenJSCode extends plugins.PluginComponent
1397
1397
1398
1398
withScopedVars(
1399
1399
currentMethodSym := sym,
1400
- thisLocalVarIdent := None ,
1400
+ thisLocalVarInfo := None ,
1401
1401
fakeTailJumpParamRepl := (NoSymbol , NoSymbol ),
1402
1402
enclosingLabelDefParams := Map .empty,
1403
1403
isModuleInitialized := new VarBox (false ),
@@ -1661,13 +1661,15 @@ abstract class GenJSCode extends plugins.PluginComponent
1661
1661
mutableLocalVars += thisSym
1662
1662
1663
1663
val thisLocalIdent = encodeLocalSym(thisSym)
1664
+ val thisLocalType = toIRType(thisSym.tpe)
1665
+
1664
1666
val genRhs = genExpr(initialThis)
1665
1667
val thisLocalVarDef = js.VarDef (thisLocalIdent,
1666
- currentClassType , thisSym.isMutable, genRhs)
1668
+ thisLocalType , thisSym.isMutable, genRhs)
1667
1669
1668
1670
val innerBody = {
1669
1671
withScopedVars(
1670
- thisLocalVarIdent := Some (thisLocalIdent)
1672
+ thisLocalVarInfo := Some (( thisLocalIdent, thisLocalType) )
1671
1673
) {
1672
1674
genInnerBody()
1673
1675
}
@@ -1687,10 +1689,11 @@ abstract class GenJSCode extends plugins.PluginComponent
1687
1689
} else {
1688
1690
assert(! static, tree.pos)
1689
1691
1692
+ val thisLocalIdent = freshLocalIdent(" this" )
1690
1693
withScopedVars(
1691
- thisLocalVarIdent := Some (freshLocalIdent( " this " ))
1694
+ thisLocalVarInfo := Some ((thisLocalIdent, jstpe. AnyType ))
1692
1695
) {
1693
- val thisParamDef = js.ParamDef (thisLocalVarIdent.get.get ,
1696
+ val thisParamDef = js.ParamDef (thisLocalIdent ,
1694
1697
jstpe.AnyType , mutable = false , rest = false )
1695
1698
1696
1699
js.MethodDef (static = true , methodName, thisParamDef :: jsParams,
@@ -1959,14 +1962,15 @@ abstract class GenJSCode extends plugins.PluginComponent
1959
1962
* is one.
1960
1963
*/
1961
1964
private def genThis ()(implicit pos : Position ): js.Tree = {
1962
- thisLocalVarIdent .fold[js.Tree ] {
1965
+ thisLocalVarInfo .fold[js.Tree ] {
1963
1966
if (tryingToGenMethodAsJSFunction) {
1964
1967
throw new CancelGenMethodAsJSFunction (
1965
1968
" Trying to generate `this` inside the body" )
1966
1969
}
1967
1970
js.This ()(currentClassType)
1968
- } { thisLocalIdent =>
1969
- js.VarRef (thisLocalIdent)(currentClassType)
1971
+ } { case (thisLocalVarIdent, thisLocalVarTpe) =>
1972
+ // .copy() to get the correct position
1973
+ js.VarRef (thisLocalVarIdent.copy())(thisLocalVarTpe)
1970
1974
}
1971
1975
}
1972
1976
0 commit comments