Skip to content

Commit d0b47d5

Browse files
committed
Improve inspection for non-local type definitions (fixes #2269)
1 parent faae912 commit d0b47d5

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/com/goide/inspections/GoMethodOnNonLocalTypeInspection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void visitMethodDeclaration(@NotNull final GoMethodDeclaration method) {
3939
if (methodType == null ||
4040
methodType.getTypeReferenceExpression() == null) return;
4141

42-
methodType = GoPsiImplUtil.findBaseTypeFromRef(methodType.getTypeReferenceExpression());
42+
methodType = GoPsiImplUtil.findTypeFromTypeRef(methodType.getTypeReferenceExpression());
4343
if (methodType == null) return;
4444

4545
String typeImportPath = ((GoFile)methodType.getContainingFile()).getImportPath();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public static GoType typeOrParameterType(@NotNull final GoTypeOwner resolve, @Nu
486486
}
487487

488488
@Nullable
489-
private static GoType findTypeFromTypeRef(@Nullable GoTypeReferenceExpression expression) {
489+
public static GoType findTypeFromTypeRef(@Nullable GoTypeReferenceExpression expression) {
490490
PsiReference reference = expression != null ? expression.getReference() : null;
491491
PsiElement resolve = reference != null ? reference.resolve() : null;
492492
if (resolve instanceof GoTypeSpec) return ((GoTypeSpec)resolve).getSpecType();

testData/highlighting/methodOnNonLocalType.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package demo2031
22

3-
import . "fmt"
3+
import (
4+
. "fmt"
5+
"time"
6+
)
7+
8+
type Duration time.Duration
49

510
func (_ *string) <error descr="Method defined on non-local type">Demo</error>() {
611

@@ -13,3 +18,8 @@ func (_ int) <error descr="Method defined on non-local type">Demo</error>() {
1318
func (_ ScanState) <error descr="Method defined on non-local type">Demo</error>() {
1419

1520
}
21+
22+
func (_ *Duration) UnmarshalText(data []byte) (err error) {
23+
_ = data
24+
return nil
25+
}

0 commit comments

Comments
 (0)