@@ -79,7 +79,7 @@ const (
7979 objXGoExec = objXGoExecOrEnv
8080)
8181
82- func compileIdent (ctx * blockCtx , ident * ast.Ident , flags int ) (pkg gogen.PkgRef , kind int ) {
82+ func compileIdent (ctx * blockCtx , lhs int , ident * ast.Ident , flags int ) (pkg gogen.PkgRef , kind int ) {
8383 fvalue := (flags & clIdentSelectorExpr ) != 0 || (flags & clIdentLHS ) == 0
8484 cb := ctx .cb
8585 name := ident .Name
@@ -108,7 +108,7 @@ func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (pkg gogen.PkgRef,
108108 if chkFlag & clIdentSelectorExpr != 0 { // TODO(xsw): remove this condition
109109 chkFlag = clIdentCanAutoCall
110110 }
111- if compileMember (ctx , 0 , ident , name , chkFlag ) == nil { // class member object
111+ if compileMember (ctx , lhs , ident , name , chkFlag ) == nil { // class member object
112112 return
113113 }
114114 cb .InternalStack ().PopN (1 )
@@ -134,12 +134,12 @@ func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (pkg gogen.PkgRef,
134134 }
135135
136136 // function alias
137- if compileFuncAlias (ctx , scope , ident , flags ) {
137+ if compileFuncAlias (ctx , lhs , scope , ident , flags ) {
138138 return
139139 }
140140
141141 // object from import . "xxx"
142- if compilePkgRef (ctx , gogen.PkgRef {}, ident , flags , objPkgRef ) {
142+ if compilePkgRef (ctx , lhs , gogen.PkgRef {}, ident , flags , objPkgRef ) {
143143 return
144144 }
145145
@@ -278,7 +278,7 @@ func compileMember(ctx *blockCtx, lhs int, v ast.Node, name string, flags int) e
278278func compileExprLHS (ctx * blockCtx , expr ast.Expr ) {
279279 switch v := expr .(type ) {
280280 case * ast.Ident :
281- compileIdent (ctx , v , clIdentLHS )
281+ compileIdent (ctx , 1 , v , clIdentLHS )
282282 case * ast.IndexExpr :
283283 compileIndexExprLHS (ctx , v )
284284 case * ast.SelectorExpr :
@@ -329,7 +329,7 @@ func compileExpr(ctx *blockCtx, lhs int, expr ast.Expr, inFlags ...int) {
329329 if cmdNoArgs {
330330 flags |= clCommandIdent // for support XGo_Exec, see TestSpxXGoExec
331331 }
332- _ , kind := compileIdent (ctx , v , flags )
332+ _ , kind := compileIdent (ctx , lhs , v , flags )
333333 if cmdNoArgs || kind == objXGoExecOrEnv {
334334 cb := ctx .cb
335335 if kind == objXGoExecOrEnv {
@@ -492,7 +492,7 @@ func compileSliceExpr(ctx *blockCtx, v *ast.SliceExpr) { // x[i:j:k]
492492func compileSelectorExprLHS (ctx * blockCtx , v * ast.SelectorExpr ) {
493493 switch x := v .X .(type ) {
494494 case * ast.Ident :
495- if at , kind := compileIdent (ctx , x , clIdentLHS | clIdentSelectorExpr ); kind != objNormal {
495+ if at , kind := compileIdent (ctx , 1 , x , clIdentLHS | clIdentSelectorExpr ); kind != objNormal {
496496 ctx .cb .VarRef (at .Ref (v .Sel .Name ))
497497 return
498498 }
@@ -602,8 +602,8 @@ func convMapToNodeSet(cb *gogen.CodeBuilder) {
602602func compileSelectorExpr (ctx * blockCtx , lhs int , v * ast.SelectorExpr , flags int ) {
603603 switch x := v .X .(type ) {
604604 case * ast.Ident :
605- if at , kind := compileIdent (ctx , x , flags | clIdentCanAutoCall | clIdentSelectorExpr ); kind != objNormal {
606- if compilePkgRef (ctx , at , v .Sel , flags , kind ) {
605+ if at , kind := compileIdent (ctx , 1 , x , flags | clIdentCanAutoCall | clIdentSelectorExpr ); kind != objNormal {
606+ if compilePkgRef (ctx , 1 , at , v .Sel , flags , kind ) {
607607 return
608608 }
609609 if token .IsExported (v .Sel .Name ) {
@@ -663,7 +663,7 @@ func unquote(name string) string {
663663 return s
664664}
665665
666- func compileFuncAlias (ctx * blockCtx , scope * types.Scope , x * ast.Ident , flags int ) bool {
666+ func compileFuncAlias (ctx * blockCtx , lhs int , scope * types.Scope , x * ast.Ident , flags int ) bool {
667667 name := x .Name
668668 if c := name [0 ]; c >= 'a' && c <= 'z' {
669669 name = string (rune (c )+ ('A' - 'a' )) + name [1 :]
@@ -672,7 +672,7 @@ func compileFuncAlias(ctx *blockCtx, scope *types.Scope, x *ast.Ident, flags int
672672 o = scope .Lookup (name )
673673 }
674674 if o != nil {
675- return identVal (ctx , x , flags , o , true )
675+ return identVal (ctx , lhs , x , flags , o , true )
676676 }
677677 }
678678 return false
@@ -710,7 +710,7 @@ func lookupPkgRef(ctx *blockCtx, pkg gogen.PkgRef, x *ast.Ident, pkgKind int) (o
710710}
711711
712712// allow at.Types to be nil
713- func compilePkgRef (ctx * blockCtx , at gogen.PkgRef , x * ast.Ident , flags , pkgKind int ) bool {
713+ func compilePkgRef (ctx * blockCtx , lhs int , at gogen.PkgRef , x * ast.Ident , flags , pkgKind int ) bool {
714714 if v , alias := lookupPkgRef (ctx , at , x , pkgKind ); v != nil {
715715 if (flags & clIdentLHS ) != 0 {
716716 if rec := ctx .recorder (); rec != nil {
@@ -719,12 +719,12 @@ func compilePkgRef(ctx *blockCtx, at gogen.PkgRef, x *ast.Ident, flags, pkgKind
719719 ctx .cb .VarRef (v , x )
720720 return true
721721 }
722- return identVal (ctx , x , flags , v , alias )
722+ return identVal (ctx , lhs , x , flags , v , alias )
723723 }
724724 return false
725725}
726726
727- func identVal (ctx * blockCtx , x * ast.Ident , flags int , v types.Object , alias bool ) bool {
727+ func identVal (ctx * blockCtx , lhs int , x * ast.Ident , flags int , v types.Object , alias bool ) bool {
728728 autocall := false
729729 if alias {
730730 if autocall = (flags & clIdentCanAutoCall ) != 0 ; autocall {
@@ -738,7 +738,7 @@ func identVal(ctx *blockCtx, x *ast.Ident, flags int, v types.Object, alias bool
738738 }
739739 cb := ctx .cb .Val (v , x )
740740 if autocall {
741- cb .CallWith (0 , 0 , 0 , x )
741+ cb .CallWith (0 , lhs , 0 , x )
742742 }
743743 return true
744744}
@@ -837,7 +837,7 @@ func compileCallExpr(ctx *blockCtx, lhs int, v *ast.CallExpr, inFlags int) {
837837 if v .IsCommand () { // for support XGo_Exec, see TestSpxXGoExec
838838 inFlags |= clCommandIdent
839839 }
840- if _ , kind := compileIdent (ctx , fn , clIdentAllowBuiltin | inFlags ); kind == objXGoExec {
840+ if _ , kind := compileIdent (ctx , 1 , fn , clIdentAllowBuiltin | inFlags ); kind == objXGoExec {
841841 args := make ([]ast.Expr , 1 , len (v .Args )+ 1 )
842842 args [0 ] = toBasicLit (fn )
843843 args = append (args , v .Args ... )
@@ -846,7 +846,7 @@ func compileCallExpr(ctx *blockCtx, lhs int, v *ast.CallExpr, inFlags int) {
846846 ifn = fn
847847 }
848848 case * ast.SelectorExpr :
849- compileSelectorExpr (ctx , lhs , fn , 0 )
849+ compileSelectorExpr (ctx , 1 , fn , 0 )
850850 case * ast.ErrWrapExpr :
851851 if v .IsCommand () {
852852 callExpr := * v
@@ -858,7 +858,7 @@ func compileCallExpr(ctx *blockCtx, lhs int, v *ast.CallExpr, inFlags int) {
858858 }
859859 compileErrWrapExpr (ctx , 1 , fn , 0 )
860860 default :
861- compileExpr (ctx , 0 , fn , clInCallExpr )
861+ compileExpr (ctx , 1 , fn , clInCallExpr )
862862 }
863863 var err error
864864 var stk = ctx .cb .InternalStack ()
@@ -1083,7 +1083,7 @@ func compileCallArgs(ctx *blockCtx, lhs int, pfn *gogen.Element, fn *fnType, v *
10831083 case * ast.LambdaExpr :
10841084 if fn .typeparam {
10851085 needInferFunc = true
1086- compileIdent (ctx , ast .NewIdent ("nil" ), 0 )
1086+ compileIdent (ctx , 0 , ast .NewIdent ("nil" ), 0 ) // TODO(xsw): check lhs
10871087 continue
10881088 }
10891089 sig , e := checkLambdaFuncType (ctx , expr , t , clLambaArgument , v .Fun )
@@ -1096,7 +1096,7 @@ func compileCallArgs(ctx *blockCtx, lhs int, pfn *gogen.Element, fn *fnType, v *
10961096 case * ast.LambdaExpr2 :
10971097 if fn .typeparam {
10981098 needInferFunc = true
1099- compileIdent (ctx , ast .NewIdent ("nil" ), 0 )
1099+ compileIdent (ctx , 0 , ast .NewIdent ("nil" ), 0 ) // TODO(xsw): check lhs
11001100 continue
11011101 }
11021102 sig , e := checkLambdaFuncType (ctx , expr , t , clLambaArgument , v .Fun )
@@ -1956,17 +1956,12 @@ func compileErrWrapExpr(ctx *blockCtx, lhs int, v *ast.ErrWrapExpr, inFlags int)
19561956 if ! useClosure && (cb .Scope ().Parent () == types .Universe ) {
19571957 panic ("TODO: can't use expr? in global" )
19581958 }
1959- expr := v .X
1960- switch expr .(type ) {
1961- case * ast.Ident , * ast.SelectorExpr :
1962- expr = & ast.CallExpr {Fun : expr , NoParenEnd : expr .End ()}
1963- }
19641959 if lhs != 0 {
19651960 // lhs == 0 means the result is discarded
19661961 // +1 accounts for the error value that will be stripped from the result tuple
19671962 lhs ++
19681963 }
1969- compileExpr (ctx , lhs , expr , inFlags )
1964+ compileExpr (ctx , lhs , v . X , inFlags )
19701965 x := cb .InternalStack ().Pop ()
19711966 n := 0
19721967 results , ok := x .Type .(* types.Tuple )
0 commit comments