Skip to content

Commit

Permalink
Fix ConstructorResolutionLogic possible ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
jlerbsc committed Nov 3, 2020
1 parent 9399d3f commit 30742f9
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

package com.github.javaparser.symbolsolver.resolution;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.github.javaparser.resolution.MethodAmbiguityException;
import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
Expand All @@ -29,12 +35,6 @@
import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Fred Lefévère-Laoide
*/
Expand Down Expand Up @@ -187,17 +187,18 @@ public static SymbolReference<ResolvedConstructorDeclaration> findMostApplicable
// we expect the methods to be ordered such that inherited methods are later in the list
}
}
}
if (possibleAmbiguity) {
// pick the first exact match if it exists
if (!MethodResolutionLogic.isExactMatch(winningCandidate, argumentsTypes)) {
if (MethodResolutionLogic.isExactMatch(other, argumentsTypes)) {
winningCandidate = other;
} else {
throw new MethodAmbiguityException("Ambiguous constructor call: cannot find a most applicable constructor: " + winningCandidate + ", " + other);
if (possibleAmbiguity) {
// pick the first exact match if it exists
if (!MethodResolutionLogic.isExactMatch(winningCandidate, argumentsTypes)) {
if (MethodResolutionLogic.isExactMatch(other, argumentsTypes)) {
winningCandidate = other;
} else {
throw new MethodAmbiguityException("Ambiguous constructor call: cannot find a most applicable constructor: " + winningCandidate + ", " + other);
}
}
}
}

return SymbolReference.solved(winningCandidate);
}
}
Expand Down

0 comments on commit 30742f9

Please sign in to comment.