Skip to content

Commit 4085741

Browse files
committed
variables with same name as struct fields are masked by struct fields, fix #1531
1 parent eb37dd3 commit 4085741

File tree

6 files changed

+19
-1
lines changed

6 files changed

+19
-1
lines changed

gen/com/goide/psi/GoTypeSpec.java

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/com/goide/psi/impl/GoTypeSpecImpl.java

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grammars/go.bnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ TypeDeclaration ::= 'type' ( TypeSpec | '(' TypeSpecs? ')' ) {pin(".*")=1}
244244
private TypeSpecs ::= TypeSpec (semi TypeSpec)* semi? {pin=1}
245245
TypeSpec ::= identifier Type {
246246
pin=1
247-
methods=[getGoType getMethods]
247+
methods=[getGoType getMethods shouldGoDeeper]
248248
stubClass="com.goide.stubs.GoTypeSpecStub"
249249
}
250250

src/com/goide/psi/impl/GoPsiImplUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,10 @@ public static boolean shouldGoDeeper(@SuppressWarnings("UnusedParameters") GoImp
788788
return false;
789789
}
790790

791+
public static boolean shouldGoDeeper(@SuppressWarnings("UnusedParameters") GoTypeSpec o) {
792+
return false;
793+
}
794+
791795
public static boolean isForSideEffects(@NotNull GoImportSpec o) {
792796
return "_".equals(o.getAlias());
793797
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
func main() {
4+
type demo struct { Field1 int }
5+
var /*def*/Field1 int
6+
/*ref*/Field1 = 1
7+
}

tests/com/goide/psi/legacy/GoLegacyResolveVarsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class GoLegacyResolveVarsTest extends GoLegacyResolveTestBase {
5656
public void testVarInSwitchTypeWithNamedSwitchGuard() { doTest(); }
5757
public void testVarDeclarationInSelectCommClauseSend() { doTest(); }
5858
public void testVarDeclarationOutsideSwitch() { doTest(); }
59+
public void testVarVsInnerTypes() { doTest(); }
5960

6061
public void testFromDefaultImportedPackage() { doDirTest(); }
6162
public void testLocalPackageDefinitionsShouldBeResolvedFirst() { doDirTest(); }

0 commit comments

Comments
 (0)