Search in sources :

Example 1 with CovariantTypeVarType

use of dyvilx.tools.compiler.ast.type.typevar.CovariantTypeVarType in project Dyvil by Dyvil.

the class AbstractMethod method checkTypeVarsInferred.

private void checkTypeVarsInferred(MarkerList markers, SourcePosition position, GenericData genericData) {
    if (this.typeParameters == null) {
        return;
    }
    final int count = this.typeParameters.size();
    genericData.lock(count);
    for (int i = 0; i < count; i++) {
        final ITypeParameter typeParameter = this.typeParameters.get(i);
        final IType typeArgument = genericData.resolveType(typeParameter);
        if (typeArgument == null || typeArgument instanceof CovariantTypeVarType) {
            final IType inferredType = typeParameter.getUpperBound();
            markers.add(Markers.semantic(position, "method.typevar.infer", this.name, typeParameter.getName(), inferredType));
            genericData.addMapping(typeParameter, inferredType);
        } else if (!typeParameter.isAssignableFrom(typeArgument, genericData)) {
            final Marker marker = Markers.semanticError(position, "method.typevar.incompatible", this.name, typeParameter.getName());
            marker.addInfo(Markers.getSemantic("type.generic.argument", typeArgument));
            marker.addInfo(Markers.getSemantic("type_parameter.declaration", typeParameter));
            markers.add(marker);
        }
    }
}
Also used : ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) CovariantTypeVarType(dyvilx.tools.compiler.ast.type.typevar.CovariantTypeVarType) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)1 IType (dyvilx.tools.compiler.ast.type.IType)1 CovariantTypeVarType (dyvilx.tools.compiler.ast.type.typevar.CovariantTypeVarType)1 Marker (dyvilx.tools.parsing.marker.Marker)1