use of dyvilx.tools.compiler.ast.generic.ITypeParameter 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);
}
}
}
use of dyvilx.tools.compiler.ast.generic.ITypeParameter in project Dyvil by Dyvil.
the class CodeMethod method writeBridgeTypeParameters.
private void writeBridgeTypeParameters(MethodWriter methodWriter, IMethod overrideMethod) {
if (this.typeParameters != null) {
final TypeParameterList overrideTypeParams = overrideMethod.getTypeParameters();
for (int i = 0, count = this.typeParameters.size(); i < count; i++) {
final ITypeParameter thisParameter = this.typeParameters.get(i);
final Reified.Type reifiedType = thisParameter.getReifiedKind();
if (reifiedType == null) {
continue;
}
final ITypeParameter overrideParameter = overrideTypeParams.get(i);
this.writeReifyArgument(methodWriter, thisParameter, reifiedType, overrideParameter);
// Extra type parameters from the overridden method are ignored
}
}
}
use of dyvilx.tools.compiler.ast.generic.ITypeParameter in project Dyvil by Dyvil.
the class ReferenceType method inferTypes.
@Override
public void inferTypes(IType concrete, ITypeContext typeContext) {
if (!this.theClass.isTypeParametric()) {
return;
}
final ITypeParameter typeVariable = this.theClass.getTypeParameters().get(0);
final IType concreteRefType = concrete.resolveType(typeVariable);
if (concreteRefType != null) {
this.type.inferTypes(concreteRefType, typeContext);
}
}
use of dyvilx.tools.compiler.ast.generic.ITypeParameter in project Dyvil by Dyvil.
the class AbstractConstructor method checkArguments.
@Override
public IType checkArguments(MarkerList markers, SourcePosition position, IContext context, IType type, ArgumentList arguments) {
final IClass theClass = this.enclosingClass;
if (!theClass.isTypeParametric()) {
for (int i = 0, count = this.parameters.size(); i < count; i++) {
arguments.checkValue(i, this.parameters.get(i), null, position, markers, context);
}
return type;
}
final IType classType = theClass.getThisType();
final GenericData genericData = new GenericData(theClass);
classType.inferTypes(type, genericData);
genericData.lockAvailable();
// Check Values and infer Types
for (int i = 0, count = this.parameters.size(); i < count; i++) {
arguments.checkValue(i, this.parameters.get(i), genericData, position, markers, context);
}
genericData.lockAvailable();
// Check Type Var Inference and Compatibility
final TypeParameterList typeParams = theClass.getTypeParameters();
for (int i = 0, count = typeParams.size(); i < count; i++) {
final ITypeParameter typeParameter = typeParams.get(i);
final IType typeArgument = genericData.resolveType(typeParameter);
if (typeArgument == null) {
final IType inferredType = typeParameter.getUpperBound();
markers.add(Markers.semantic(position, "constructor.typevar.infer", theClass.getName(), typeParameter.getName(), inferredType));
genericData.addMapping(typeParameter, inferredType);
} else if (!typeParameter.isAssignableFrom(typeArgument, genericData)) {
final Marker marker = Markers.semanticError(position, "constructor.typevar.incompatible", theClass.getName(), typeParameter.getName());
marker.addInfo(Markers.getSemantic("type.generic.argument", typeArgument));
marker.addInfo(Markers.getSemantic("type_parameter.declaration", typeParameter));
markers.add(marker);
}
}
return classType.getConcreteType(genericData);
}
use of dyvilx.tools.compiler.ast.generic.ITypeParameter in project Dyvil by Dyvil.
the class ClassGenericType method inferTypes.
@Override
public void inferTypes(IType concrete, ITypeContext typeContext) {
final TypeParameterList classTypeParams = this.getTheClass().getTypeParameters();
for (int i = 0, size = this.arguments.size(); i < size; i++) {
final ITypeParameter typeVar = classTypeParams.get(i);
final IType concreteType = concrete.resolveType(typeVar);
if (concreteType != null) {
this.arguments.get(i).inferTypes(concreteType, typeContext);
}
}
}
Aggregations