-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unresolved struct field inspection #2892
base: master
Are you sure you want to change the base?
Conversation
GoStructType structType = ObjectUtils.tryCast(startElement, GoStructType.class); | ||
if (structType == null) return; | ||
List<GoFieldDeclaration> declarations = structType.getFieldDeclarationList(); | ||
PsiElement anchor = !declarations.isEmpty() ? ContainerUtil.getLastItem(declarations) : structType.getLbrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= ContainerUtil.getLastItem(declarations, structType.getLbrace)
if (structType == null) return; | ||
List<GoFieldDeclaration> declarations = structType.getFieldDeclarationList(); | ||
PsiElement anchor = !declarations.isEmpty() ? ContainerUtil.getLastItem(declarations) : structType.getLbrace(); | ||
if (anchor != null) structType.addAfter(GoElementFactory.createFieldDeclaration(project, myFieldText, myTypeText), anchor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When can it happen? Can you test this?
GoType type = qualifier != null ? qualifier.getGoType(null) : null; | ||
GoStructType structType = type != null ? ObjectUtils.tryCast(type.getUnderlyingType(), GoStructType.class) : null; | ||
if (!"_".equals(reference.getCanonicalText()) && structType != null) { | ||
fixes = new LocalQuickFix[]{new GoAddStructFieldFix(reference.getCanonicalText(), getTypeName(o), structType)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually, psi element that is passed to QuickFix is an inspection holder. In this case you pass there the element that should be changed, not the unresolved element. It's bad, because the struct type or unresolved reference could completely changed on the moment of quickfix invocation and should not be modified,
a2737bd
to
2558b51
Compare
No description provided.