use of dyvilx.tools.compiler.ast.type.compound.TupleType in project Dyvil by Dyvil.
the class UnapplyPattern method withMethod.
protected boolean withMethod(IType matchedType, IValue methodCall, MarkerList markers) {
final IType type = NullableType.unapply(methodCall.getType());
final String className = type.getInternalName();
if (// return type must be a tuple type
!className.startsWith("dyvil/tuple/Tuple$Of")) {
return false;
}
final TupleType tupleType = type.extract(TupleType.class);
final TypeList typeArguments = tupleType.getArguments();
if (this.patternCount != typeArguments.size()) {
final Marker marker = Markers.semanticError(this.position, "pattern.unapply.count", this.type.toString());
marker.addInfo(Markers.getSemantic("pattern.unapply.count.pattern", this.patternCount));
marker.addInfo(Markers.getSemantic("pattern.unapply.count.class", typeArguments.size()));
markers.add(marker);
return true;
}
this.unapplyCall = methodCall;
for (int i = 0; i < this.patternCount; i++) {
final IType subType = typeArguments.get(i);
final Pattern pattern = this.patterns[i];
final Pattern typedPattern = pattern.withType(subType, markers);
if (typedPattern == null) {
final Marker marker = Markers.semanticError(this.position, "pattern.unapply.type");
marker.addInfo(Markers.getSemantic("pattern.type", pattern.getType()));
marker.addInfo(Markers.getSemantic("classparameter.type", subType));
markers.add(marker);
} else {
this.patterns[i] = typedPattern;
}
}
this.switchValue = getSwitchValue(matchedType, this.type);
return true;
}
Aggregations