Search in sources :

Example 1 with TypeCheckPattern

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;
}
Also used : TypeCheckPattern(dyvilx.tools.compiler.ast.pattern.TypeCheckPattern) AbstractPattern(dyvilx.tools.compiler.ast.pattern.AbstractPattern) TypeCheckPattern(dyvilx.tools.compiler.ast.pattern.TypeCheckPattern) Pattern(dyvilx.tools.compiler.ast.pattern.Pattern) TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IClass (dyvilx.tools.compiler.ast.classes.IClass)1 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)1 AbstractPattern (dyvilx.tools.compiler.ast.pattern.AbstractPattern)1 Pattern (dyvilx.tools.compiler.ast.pattern.Pattern)1 TypeCheckPattern (dyvilx.tools.compiler.ast.pattern.TypeCheckPattern)1 IType (dyvilx.tools.compiler.ast.type.IType)1 Marker (dyvilx.tools.parsing.marker.Marker)1