use of dyvilx.tools.compiler.ast.pattern.TypeCheckPattern in project Dyvil by Dyvil.
the class TupleSurrogate method withType.
@Override
public Pattern withType(IType type, MarkerList markers) {
final IClass tupleClass = TupleType.getTupleClass(this.patternCount);
if (tupleClass == null) {
return null;
}
final IType tupleType = tupleClass.getClassType();
if (!Types.isSuperClass(type, tupleType)) {
return null;
}
// reset type to recompute it later
this.tupleType = null;
final TypeParameterList typeParameters = tupleClass.getTypeParameters();
for (int i = 0; i < this.patternCount; i++) {
final IType elementType = Types.resolveTypeSafely(type, typeParameters.get(i));
final Pattern pattern = this.patterns[i];
final Pattern typedPattern = pattern.withType(elementType, markers);
if (typedPattern == null) {
final Marker marker = Markers.semanticError(pattern.getPosition(), "pattern.tuple.element.type");
marker.addInfo(Markers.getSemantic("pattern.type", pattern.getType()));
marker.addInfo(Markers.getSemantic("tuple.element.type", elementType));
markers.add(marker);
} else {
this.patterns[i] = typedPattern;
}
}
if (!Types.isSuperClass(tupleType, type)) {
return new TypeCheckPattern(this, type, tupleType);
}
return this;
}
Aggregations