} else {
rawParameters = null;
target = null;
}
NameID candidateID = null;
Nominal.FunctionOrMethod candidateType = null;
for (Pair<NameID, Nominal.FunctionOrMethod> p : candidates) {
Nominal.FunctionOrMethod nft = p.second();
Type.FunctionOrMethod ft = nft.raw();
if (parameters == null || paramSubtypes(ft, target)) {
// this is now a genuine candidate
if (candidateType == null
|| paramStrictSubtypes(candidateType.raw(), ft)) {
candidateType = nft;
candidateID = p.first();
} else if (!paramStrictSubtypes(ft, candidateType.raw())) {
// this is an ambiguous error
String msg = name + parameterString(parameters)
+ " is ambiguous";
// FIXME: should report all ambiguous matches here
msg += "\n\tfound: " + candidateID + " : "
+ candidateType.nominal();
msg += "\n\tfound: " + p.first() + " : "
+ p.second().nominal();
throw new ResolveError(msg);
}
}
}
if (candidateType == null) {
// second, didn't find matching message so generate error message
String msg = "no match for " + name + parameterString(parameters);
for (Pair<NameID, Nominal.FunctionOrMethod> p : candidates) {
msg += "\n\tfound: " + p.first() + " : " + p.second().nominal();
}
throw new ResolveError(msg);
} else {
// now check protection modifier
WhileyFile wf = builder.getSourceFile(candidateID.module());
if (wf != null) {
if (wf != context.file()) {
for (WhileyFile.FunctionOrMethod d : wf.declarations(
WhileyFile.FunctionOrMethod.class,
candidateID.name())) {
if (d.parameters.equals(candidateType.params())) {
if (!d.hasModifier(Modifier.PUBLIC)
&& !d.hasModifier(Modifier.PROTECTED)) {
String msg = candidateID.module() + "." + name
+ parameterString(parameters)
+ " is not visible";
throw new ResolveError(msg);
}
}
}
}
} else {
WyilFile m = builder.getModule(candidateID.module());
WyilFile.FunctionOrMethodDeclaration d = m.functionOrMethod(
candidateID.name(), candidateType.raw());
if (!d.hasModifier(Modifier.PUBLIC)
&& !d.hasModifier(Modifier.PROTECTED)) {
String msg = candidateID.module() + "." + name
+ parameterString(parameters) + " is not visible";
throw new ResolveError(msg);
}
}
}