Skip to content

Commit

Permalink
Fix resolved pattern declaration resolution check for null
Browse files Browse the repository at this point in the history
  • Loading branch information
biboudis committed Aug 31, 2024
1 parent 69d7f7f commit c3b8f0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4344,7 +4344,7 @@ public void visitRecordPattern(JCRecordPattern tree) {
List<MethodSymbol> patternDeclarations = getPatternDeclarationCandidates(site, nestedPatternCount);

if (patternDeclarations.size() >= 1) {
MethodSymbol patternDeclaration = null;
MethodSymbol resolvedPatternDeclaration = null;

if (patternDeclarations.size() > 1) {
// precalculate types of pattern components (as in method invocation)
Expand All @@ -4355,14 +4355,14 @@ public void visitRecordPattern(JCRecordPattern tree) {
}
List<Type> patternTypes = patternTypesBuffer.toList();

patternDeclaration = selectBestPatternDeclarationInScope(tree, site, patternDeclarations, patternTypes);
resolvedPatternDeclaration = selectBestPatternDeclarationInScope(tree, site, patternDeclarations, patternTypes);
} else {
patternDeclaration = patternDeclarations.getFirst();
resolvedPatternDeclaration = patternDeclarations.getFirst();
}

if (patternDeclaration != null) {
expectedRecordTypes = types.memberType(site, patternDeclaration).getBindingTypes();
tree.patternDeclaration = patternDeclaration;
if (resolvedPatternDeclaration != null) {
expectedRecordTypes = types.memberType(site, resolvedPatternDeclaration).getBindingTypes();
tree.patternDeclaration = resolvedPatternDeclaration;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3572,8 +3572,9 @@ public PatternDescription makePatternDescription(Type selectorType, JCPattern pa
} else if (pattern instanceof JCRecordPattern record) {
Type[] componentTypes;

if (!record.type.isErroneous()) {
componentTypes = ((JCRecordPattern) pattern).patternDeclaration.type.asMethodType().bindingtypes.toArray(Type[]::new);
MethodSymbol patternDeclaration = ((JCRecordPattern) pattern).patternDeclaration;
if (!record.type.isErroneous() && patternDeclaration != null) {
componentTypes = patternDeclaration.type.asMethodType().bindingtypes.toArray(Type[]::new);
}
else {
componentTypes = record.nested.map(t -> types.createErrorType(t.type)).toArray(s -> new Type[s]);;
Expand Down

0 comments on commit c3b8f0e

Please sign in to comment.