From e0959bd1d959db4de7805d6cf949ed152a9d270d Mon Sep 17 00:00:00 2001 From: Li <2188718831@qq.com> Date: Fri, 27 Nov 2026 08:57:41 +0000 Subject: [PATCH] =?UTF-8?q?fix(navigation):=20=E4=BF=9D=E7=95=99=E9=87=8D?= =?UTF-8?q?=E8=BD=BD=E8=A7=A3=E6=9E=90=E4=B8=AD=E7=9A=84=20Java=20?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E7=BB=B4=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #5 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- internal/codenav/implementations.go | 9 +- internal/codenav/implementations_test.go | 34 +++++ internal/codenav/jdtls_cases_test.go | 81 ++++++++++++ internal/codenav/overloads.go | 154 ++++++++++++++--------- internal/codenav/parse.go | 44 +++++-- internal/codenav/resolve.go | 86 ++++++------- 6 files changed, 296 insertions(+), 112 deletions(-) diff --git a/internal/codenav/implementations.go b/internal/codenav/implementations.go index f6bdf86..1ba0467 100644 --- a/internal/codenav/implementations.go +++ b/internal/codenav/implementations.go @@ -423,7 +423,7 @@ func methodsOverrideMatch(base, sub *Member) bool { if base.Kind != kMethod || sub.Kind != kMethod || base.Name != sub.Name { return false } - if base.Arity != sub.Arity || base.Varargs != sub.Varargs { + if base.Arity != sub.Arity { return false } if base.Params == sub.Params || base.Params == "" || sub.Params == "" { @@ -438,8 +438,11 @@ func methodsOverrideMatch(base, sub *Member) bool { if bParts[i] == sParts[i] { continue } - // Allow single-identifier generic type parameters (e.g. T -> String) in subclasses. - if isGenericTypeParam(bParts[i]) || isGenericTypeParam(sParts[i]) { + // Allow a type variable to stand for a substituted type, also as an array component. + bType, sType := bParts[i], sParts[i] + bElem, sElem := strings.TrimRight(bType, "[]"), strings.TrimRight(sType, "[]") + bDims, sDims := len(bType)-len(bElem), len(sType)-len(sElem) + if bDims <= sDims && isGenericTypeParam(bElem) || sDims <= bDims && isGenericTypeParam(sElem) { continue } return false diff --git a/internal/codenav/implementations_test.go b/internal/codenav/implementations_test.go index 05c4b41..4975658 100644 --- a/internal/codenav/implementations_test.go +++ b/internal/codenav/implementations_test.go @@ -129,6 +129,40 @@ class Caller { } } +func TestArraySignatureImplementations(t *testing.T) { + const base = `package demo; + +interface Buffer { + void write(String text); + void write(String... texts); + void put(T[] values); +} +` + const sub = `package demo; + +class TextBuffer implements Buffer { + public void write(String text) {} + public void write(String[] texts) {} + public void put(String[] values) {} +} +` + const basePath, subPath = "demo/Buffer.java", "demo/TextBuffer.java" + ix := buildNavIndex(map[string]string{basePath: base, subPath: sub}) + for _, tt := range []struct{ baseMethod, subMethod string }{ + {"write(String text)", "write(String text)"}, + {"write(String... texts)", "write(String[] texts)"}, + {"put(T[] values)", "put(String[] values)"}, + } { + t.Run(tt.baseMethod, func(t *testing.T) { + got := ix.Implementations(basePath, []byte(base), indexOf(base, tt.baseMethod)) + want := declAtSrc(t, subPath, sub, tt.subMethod) + if len(got) != 1 || got[0].Path != want.Path || got[0].Line != want.Line || got[0].Column != want.Column { + t.Fatalf("implementations = %+v, want only %+v", got, want) + } + }) + } +} + func TestCyclicInheritanceGuardDoesNotLoop(t *testing.T) { aSrc := "package cyc; class A extends B { void m() {} }\n" bSrc := "package cyc; class B extends A { void m() {} }\n" diff --git a/internal/codenav/jdtls_cases_test.go b/internal/codenav/jdtls_cases_test.go index bde2c32..21f91f6 100644 --- a/internal/codenav/jdtls_cases_test.go +++ b/internal/codenav/jdtls_cases_test.go @@ -125,6 +125,87 @@ func TestOverloadsWithTheSameArity(t *testing.T) { } } +func TestArrayOverloads(t *testing.T) { + const path = "src/p/Use.java" + const src = `package p; +import java.nio.charset.Charset; +import static java.nio.charset.StandardCharsets.UTF_8; + +class Buffer { + void write(int value) {} + void write(byte[] bytes) {} + void write(byte rows[][]) {} + void collect(Object value) {} + void collect(byte... values) {} + void select(Object value) {} + void select(CharSequence[] values) {} + void read(byte[] values, String tag) {} + void read(java.io.InputStream stream, Object tag) {} +} + +class Key { + byte[] getBytes(Charset charset) { return new byte[0]; } + byte getLegacy()[] { return new byte[0]; } + byte bytes[] = new byte[0]; +} + +class Result { + T getData() { return null; } +} + +class Use { + void run(Buffer buffer, Key key, Result result, byte... rest) { + byte rows[][] = new byte[1][1]; + buffer.write(key.getBytes(UTF_8)); + buffer.write(42); + buffer.write(rows); + buffer.write(rows[0]); + buffer.write(rows[0][0]); + buffer.write(new byte[]{1}); + buffer.write((byte[]) null); + buffer.write((key.getLegacy())); + buffer.write(key.bytes); + buffer.write(rest); + buffer.write(rest[0]); + buffer.collect(new byte[1]); + buffer.collect((byte) 1); + buffer.collect((byte) 1, (byte) 2); + buffer.select(new String[1]); + buffer.read(result.getData(), "data"); + } +} +` + ix := NewIndex() + ix.Put(ParseFile(path, []byte(src))) + for _, test := range []struct{ call, decl string }{ + {"write(key.getBytes(UTF_8))", "write(byte[] bytes)"}, + {"write(42)", "write(int value)"}, + {"write(rows)", "write(byte rows[][])"}, + {"write(rows[0])", "write(byte[] bytes)"}, + {"write(rows[0][0])", "write(int value)"}, + {"write(new byte[]{1})", "write(byte[] bytes)"}, + {"write((byte[]) null)", "write(byte[] bytes)"}, + {"write((key.getLegacy()))", "write(byte[] bytes)"}, + {"write(key.bytes)", "write(byte[] bytes)"}, + {"write(rest)", "write(byte[] bytes)"}, + {"write(rest[0])", "write(int value)"}, + {"collect(new byte[1])", "collect(byte... values)"}, + {"collect((byte) 1)", "collect(Object value)"}, + {"collect((byte) 1, (byte) 2)", "collect(byte... values)"}, + {"select(new String[1])", "select(CharSequence[] values)"}, + {`read(result.getData(), "data")`, "read(byte[] values, String tag)"}, + } { + t.Run(test.call, func(t *testing.T) { + off := offsetOf(t, src, test.call, 0, 0) + got, ok := ix.Resolve(path, []byte(src), off) + want := declAtSrc(t, path, src, test.decl) + if !ok || got.Path != want.Path || got.Line != want.Line || got.Column != want.Column { + t.Fatalf("got %v (resolved %v), want %v", got, ok, want) + } + }) + } +} + var jdtlsCaseProject = map[string]string{ "src/q/Manager.java": `package q; diff --git a/internal/codenav/overloads.go b/internal/codenav/overloads.go index c5458b8..f160fa7 100644 --- a/internal/codenav/overloads.go +++ b/internal/codenav/overloads.go @@ -25,7 +25,7 @@ func (q *qctx) callAt(open int) call { } // paramTypes returns the simple type names of the parameters between the -// parentheses at open and end (exclusive), generics and dims stripped, +// parentheses at open and end (exclusive), with array dimensions, // joined by commas and interned: members with the same signature share one // string, which keeps the index small. func (p *parser) paramTypes(open, end int) string { @@ -33,10 +33,14 @@ func (p *parser) paramTypes(open, end int) string { return "" } var out []byte - s, depth, angle := open+1, 0, 0 + s, name, depth, angle := open+1, open+1, 0, 0 for k := open + 1; k < end; k++ { switch { case k == end-1: + case p.is(k, "@"): + k, _ = p.skipAnnotation(k) + k-- + continue case p.is(k, "(") || p.is(k, "[") || p.is(k, "{"): depth++ continue @@ -50,18 +54,17 @@ func (p *parser) paramTypes(open, end int) string { angle-- continue case p.is(k, ",") && depth == 0 && angle == 0: + case p.ident(k) && depth == 0 && angle == 0: + name = k + continue default: continue } - name := k - 1 - for name > s && !p.ident(name) { // String args[] - name-- - } if len(out) > 0 { out = append(out, ',') } - out = append(out, simpleName(p.typeText(s, name))...) - s = k + 1 + out = append(out, simpleName(p.declaratorType(p.typeText(s, name), name+1))...) + s, name = k+1, k+1 } return p.in.s(out) } @@ -70,16 +73,26 @@ func simpleName(t string) string { return t[strings.LastIndexByte(t, '.')+1:] } -// argType is what an argument is known to be. name is "" when unknown; t is -// set when the type was resolved; prim names a primitive; null is the -// literal null. +// argType is what an expression is known to be. name is the simple type +// (including array dimensions), or "" when unknown. t is the declaration +// of the base type when it could be resolved. type argType struct { name string t *Type - prim string null bool } +func resolvedType(t *Type) argType { + if t == nil { + return argType{} + } + return argType{name: t.Name, t: t} +} + +func (q *qctx) declaredType(text string, f *File, ctx *Type) argType { + return argType{name: simpleName(text), t: q.resolveText(text, f, ctx)} +} + func (q *qctx) argTypes(open int) []argType { p := q.p end := p.skipBalanced(open) @@ -125,13 +138,13 @@ func (q *qctx) argTypeOf(s, e int, ctx *Type) argType { case tok.Kind == tString: return argType{name: "String"} case tok.Kind == tChar: - return argType{prim: "char"} + return argType{name: "char"} case tok.Kind == tNumber: - return argType{prim: numberType(p.txt(s))} + return argType{name: numberType(p.txt(s))} } switch p.txt(s) { case "true", "false": - return argType{prim: "boolean"} + return argType{name: "boolean"} case "null": return argType{null: true} } @@ -161,49 +174,40 @@ func (q *qctx) argTypeOf(s, e int, ctx *Type) argType { // A cast: (Foo) x, (int) y. if p.is(s, "(") { if ce := p.skipBalanced(s); ce < e && q.typeStartBack(ce-2) == s+1 && (p.ident(ce) || p.is(ce, "(") || p.toks[ce].Kind != tPunct) { - name := simpleName(p.typeText(s+1, ce-1)) - if primitives[name] { - return argType{prim: name} - } - return argType{name: name, t: q.resolveText(p.typeText(s+1, ce-1), q.file, ctx)} + return q.declaredType(p.typeText(s+1, ce-1), q.file, ctx) } } - if t := q.typeOfExpr(e-1, ctx); t != nil { - return argType{name: t.Name, t: t} - } - // Names whose declared type is written but not in the index (JDK or - // library types without sources). if p.is(s, "new") && p.ident(s+1) { k := s + 1 - for p.is(k+1, ".") && p.ident(k+2) { - k += 2 + for { + k++ + if p.is(k, "<") { + k = p.skipBalanced(k) + } + if !p.is(k, ".") || !p.ident(k+1) { + break + } + k++ } - if name := p.txt(k); !primitives[name] && (p.is(k+1, "(") || p.is(k+1, "<")) { - return argType{name: name} + typeEnd := k + dims := 0 + for k < e && p.is(k, "[") { + k = p.skipBalanced(k) + dims++ } - return argType{} - } - if e-s == 1 && p.ident(s) { - name := p.txt(s) - if l, ok := q.findLocal(name, s); ok && l.typeS >= 0 { - if text := p.typeText(l.typeS, l.typ); text != "var" { - if tn := simpleName(text); primitives[tn] { - return argType{prim: tn} - } else { - return argType{name: tn} - } - } - return argType{} + if dims > 0 && (k == e || p.is(k, "{") && p.skipBalanced(k) == e) { + return q.declaredType(p.typeText(s+1, typeEnd)+strings.Repeat("[]", dims), q.file, ctx) } - if m := q.fieldInScope(name, ctx); m != nil && m.Type != "" { - if tn := simpleName(m.Type); primitives[tn] { - return argType{prim: tn} - } else { - return argType{name: tn} + // Anonymous class bodies have the declared type for the purposes of + // overload selection. + if p.is(k, "(") { + end := p.skipBalanced(k) + if end == e || p.is(end, "{") && p.skipBalanced(end) == e { + return q.declaredType(p.typeText(s+1, typeEnd), q.file, ctx) } } } - return argType{} + return q.exprType(e-1, ctx) } func numberType(lit string) string { @@ -268,23 +272,44 @@ func (q *qctx) fit(a argType, param string) int { return -2 } return 0 - case a.prim != "": + case a.name == "" || a.t == nil && typeVar(a.name): + return 0 + case a.name == param: + return 3 + } + if elem, array := strings.CutSuffix(a.name, "[]"); array { + if paramElem, arrayParam := strings.CutSuffix(param, "[]"); arrayParam { + // Primitive arrays are invariant. Reference array components + // can widen, without boxing or unboxing. + if primitives[elem] || primitives[paramElem] { + return -2 + } + a.name = elem + if fit := q.fit(a, paramElem); fit <= 0 { + return fit + } + return 2 + } + switch param { + case "Object", "Cloneable", "Serializable": + return 1 + } + return -2 + } + if strings.HasSuffix(param, "[]") { + return -2 + } + if primitives[a.name] { switch { - case param == a.prim: - return 3 - case hasWord(widens[a.prim], param), param == boxes[a.prim]: + case hasWord(widens[a.name], param), param == boxes[a.name]: return 2 case primitives[param]: return -2 case param == "Object" || param == "Serializable" || param == "Comparable" || - param == "Number" && a.prim != "boolean" && a.prim != "char": + param == "Number" && a.name != "boolean" && a.name != "char": return 1 } return -2 - case a.name == "": - return 0 - case a.name == param: - return 3 } if primitives[param] { for prim, box := range boxes { @@ -331,18 +356,27 @@ func (q *qctx) bestOverload(ms []*Member, c call) *Member { args := q.argTypes(c.open) rank := func(m *Member) (group, score int) { ok := true + expanded := m.Varargs params := strings.Split(m.Params, ",") for k, a := range args { if m.Params == "" { break } - pk := min(k, len(params)-1) // varargs elements - f := q.fit(a, params[pk]) + pk := min(k, len(params)-1) + param := params[pk] + f := q.fit(a, param) + if m.Varargs && pk == len(params)-1 { + if k == pk && len(args) == len(params) && (a.name != "" || a.null) && f >= 0 { + expanded = false + } else { + f = q.fit(a, strings.TrimSuffix(param, "[]")) + } + } ok = ok && f >= 0 score += f } switch { - case ok && !m.Varargs: + case ok && !expanded: return 2, score case ok: return 1, score diff --git a/internal/codenav/parse.go b/internal/codenav/parse.go index 7755829..0769df1 100644 --- a/internal/codenav/parse.go +++ b/internal/codenav/parse.go @@ -83,7 +83,7 @@ const ( type Member struct { Name string Kind declKind - Type string // declared/return type, generics and dims stripped; "" for ctors + Type string // declared/return type with array dimensions, generics stripped; "" for ctors Arity int16 Varargs bool Private bool @@ -314,9 +314,10 @@ func (p *parser) skipModifiers(i int) (int, annos) { } // typeText renders the type in toks[a:b] as a dotted name without generics, -// annotations or array dimensions. +// annotations. Array dimensions and varargs use the same [] suffix. func (p *parser) typeText(a, b int) string { var sb []byte + dims := 0 for i := a; i < b; i++ { if p.is(i, "@") { i, _ = p.skipAnnotation(i) @@ -338,11 +339,40 @@ func (p *parser) typeText(a, b int) string { sb = append(sb, s...) } else if p.is(i, ".") { sb = append(sb, '.') + } else if p.is(i, "[") && i+1 < b && p.is(i+1, "]") || p.is(i, "...") { + dims++ } } + for range dims { + sb = append(sb, '[', ']') + } return p.in.s(sb) } +// arrayDimsEnd skips the dimensions that can follow a declarator name or a +// method's closing parenthesis (int a[], int f()[]). +func (p *parser) arrayDimsEnd(start int) (end, dims int) { + end = start + for k := start; ; { + if p.is(k, "@") { + k, _ = p.skipAnnotation(k) + continue + } + if !p.is(k, "[") || !p.is(k+1, "]") { + return end, dims + } + k += 2 + end, dims = k, dims+1 + } +} + +func (p *parser) declaratorType(typ string, suffix int) string { + if _, dims := p.arrayDimsEnd(suffix); dims > 0 { + return p.in.s([]byte(typ + strings.Repeat("[]", dims))) + } + return typ +} + // ParseFile reads the declarations of one Java source file for the index. // path is the repository-relative, slash-separated path the index reports // back in a Location. It is safe to call from several goroutines at once. @@ -503,9 +533,11 @@ func (p *parser) parseBody(i int, owner *Type, enum bool) int { m.Kind = kCtor } else { m.Kind = kMethod - m.Type = p.typeText(typeStart, last) } pe := p.skipBalanced(j) + if m.Kind == kMethod { + m.Type = p.declaratorType(p.typeText(typeStart, last), pe) + } m.Arity, m.Varargs = p.arity(j, pe) m.Params = p.paramTypes(j, pe) owner.Members = append(owner.Members, m) @@ -542,16 +574,14 @@ func (p *parser) parseBody(i int, owner *Type, enum bool) int { k := j name := last for { - p.addField(owner, name, ft, lb) + p.addField(owner, name, p.declaratorType(ft, name+1), lb) if p.is(k, "=") { k = p.skipExpr(k + 1) } if p.is(k, ",") && p.ident(k+1) { name = k + 1 k += 2 - for p.is(k, "[") { - k = p.skipBalanced(k) - } + k, _ = p.arrayDimsEnd(k) continue } break diff --git a/internal/codenav/resolve.go b/internal/codenav/resolve.go index 3afd2ce..81adb75 100644 --- a/internal/codenav/resolve.go +++ b/internal/codenav/resolve.go @@ -523,8 +523,9 @@ func (q *qctx) staticMemberType(name string, f *File, wild bool) *Type { return nil } -// resolveText resolves a type as written ("Foo", "Outer.Inner", "a.b.Foo"). +// resolveText finds the declaration of a type or of an array's base type. func (q *qctx) resolveText(text string, f *File, ctx *Type) *Type { + text = strings.TrimRight(text, "[]") if text == "" { return nil } @@ -807,11 +808,11 @@ func (q *qctx) fieldInScope(name string, ctx *Type) *Member { return nil } -func (q *qctx) memberType(m *Member) *Type { +func (q *qctx) memberType(m *Member) argType { if m.Kind == kEnumConst { - return m.Owner + return resolvedType(m.Owner) } - return q.resolveText(m.Type, m.Owner.File, m.Owner) + return q.declaredType(m.Type, m.Owner.File, m.Owner) } // ---- expressions ---- @@ -864,54 +865,59 @@ func (q *qctx) qualifiedType(ti int) *Type { return q.lookupFQN(strings.Join(parts, "."), q.file) } -// typeOfExpr infers the static type of the expression ending at token end. +// typeOfExpr finds the declaration used for member lookup. func (q *qctx) typeOfExpr(end int, ctx *Type) *Type { + return q.exprType(end, ctx).t +} + +// exprType infers the static type of the expression ending at token end. +func (q *qctx) exprType(end int, ctx *Type) argType { p := q.p if end < 0 || q.depth > 16 { - return nil + return argType{} } q.depth++ defer func() { q.depth-- }() switch { case p.toks[end].Kind == tString: // "text".trim(), and text blocks - return q.impliedType("java.lang.String") + return argType{name: "String", t: q.impliedType("java.lang.String")} case p.ident(end): s := p.txt(end) if p.is(end-1, ".") { switch s { case "this": // Outer.this - return q.resolveSimple(p.txt(end-2), q.file, ctx) + return resolvedType(q.resolveSimple(p.txt(end-2), q.file, ctx)) case "class": // Foo.class.getName() - return q.impliedType("java.lang.Class") + return argType{name: "Class", t: q.impliedType("java.lang.Class")} case "super": // Iface.super.m(): the interface; Outer.super.m(): Outer's superclass t := q.resolveSimple(p.txt(end-2), q.file, ctx) if t == nil || t.Kind == kInterface { - return t + return resolvedType(t) } if ss := q.superTypes(t); len(ss) > 0 { - return ss[0] + return resolvedType(ss[0]) } - return nil + return argType{} } ot := q.typeOfExpr(end-2, ctx) if ot == nil { - return q.qualifiedType(end) + return resolvedType(q.qualifiedType(end)) } if m := q.findField(ot, s); m != nil { return q.memberType(m) } - return q.findNested(ot, s) + return resolvedType(q.findNested(ot, s)) } switch s { case "this": - return ctx + return resolvedType(ctx) case "super": if ctx != nil { if ss := q.superTypes(ctx); len(ss) > 0 { - return ss[0] + return resolvedType(ss[0]) } } - return nil + return argType{} } if l, ok := q.findLocal(s, end); ok { return q.localType(l, ctx) @@ -919,11 +925,11 @@ func (q *qctx) typeOfExpr(end int, ctx *Type) *Type { if m := q.fieldInScope(s, ctx); m != nil { return q.memberType(m) } - return q.resolveSimple(s, q.file, ctx) + return resolvedType(q.resolveSimple(s, q.file, ctx)) case p.is(end, ")"): open := q.matchBack(end) if open < 0 { - return nil + return argType{} } before := open - 1 if p.is(before, ">") { // new Foo<>(...) @@ -951,10 +957,10 @@ func (q *qctx) typeOfExpr(end int, ctx *Type) *Type { for k := s; k <= before; k += 2 { parts = append(parts, p.txt(k)) } - return q.resolveText(strings.Join(parts, "."), q.file, ctx) + return q.declaredType(strings.Join(parts, "."), q.file, ctx) } if nm == "this" || nm == "super" || javaKeywords[nm] && nm != "this" { - return nil + return argType{} } c := q.callAt(open) var m *Member @@ -966,48 +972,44 @@ func (q *qctx) typeOfExpr(end int, ctx *Type) *Type { m = q.methodInScope(nm, c, ctx) } if m == nil { - return nil + return argType{} } if m.Ret != nil { - return m.Ret + return resolvedType(m.Ret) } if m.Kind == kField { // record/Lombok accessor // A chained setter compiles only if it returns this // (@Accessors(chain = true) or lombok.config). if strings.HasPrefix(nm, "set") && nm != m.Name { - return m.Owner + return resolvedType(m.Owner) } - return q.memberType(m) } - return q.resolveText(m.Type, m.Owner.File, m.Owner) - } - // cast: ((Foo) x) - if p.is(open+1, "(") { - ce := p.skipBalanced(open + 1) - return q.resolveText(p.typeText(open+2, ce-1), q.file, ctx) + return q.memberType(m) } - return q.typeOfExpr(end-1, ctx) + return q.argTypeOf(open+1, end, ctx) case p.is(end, "]"): open := q.matchBack(end) - return q.typeOfExpr(open-1, ctx) // element type: dims are not tracked + a := q.exprType(open-1, ctx) + a.name = strings.TrimSuffix(a.name, "[]") + return a } - return nil + return argType{} } -func (q *qctx) localType(l local, ctx *Type) *Type { +func (q *qctx) localType(l local, ctx *Type) argType { p := q.p if l.typeS < 0 { - return nil + return argType{} } text := p.typeText(l.typeS, l.typ) if text == "var" { if p.is(l.tok+1, "=") { e := p.skipExpr(l.tok + 2) - return q.typeOfExpr(e-1, ctx) + return q.argTypeOf(l.tok+2, e, ctx) } - return nil + return argType{} } - return q.resolveText(text, q.file, ctx) + return q.declaredType(p.declaratorType(text, l.tok+1), q.file, ctx) } // typeStartBack returns the first token of a type that ends at token e, or -1. @@ -1144,7 +1146,7 @@ func (q *qctx) findLocal(name string, at int) (local, bool) { if !p.ident(k) || javaKeywords[p.txt(k)] { continue } - nx := k + 1 + nx, _ := p.arrayDimsEnd(k + 1) ok := p.is(nx, "=") && !p.is(nx+1, "=") || p.is(nx, ";") || p.is(nx, ",") || p.is(nx, ")") || p.is(nx, ":") if !ok && (p.is(nx, "&") || p.is(nx, "|") || p.is(nx, "?")) { if ts := q.typeStartBack(k - 1); ts > 0 && p.is(ts-1, "instanceof") { @@ -1159,9 +1161,9 @@ func (q *qctx) findLocal(name string, at int) (local, bool) { te = k - 1 } if ts := q.typeStartBack(te - 1); ts >= 0 { - add(k, ts, te) + add(k, ts, k) if !p.is(nx, ")") && !p.is(nx, ":") { - multi, multiDepth = &local{k, ts, te}, depth + multi, multiDepth = &local{k, ts, k}, depth } } else if multi != nil && depth == multiDepth && p.is(k-1, ",") && !p.is(nx, ":") { add(k, multi.typeS, multi.typ)