use of dyvilx.tools.compiler.ast.generic.ITypeContext in project Dyvil by Dyvil.
the class LambdaExpr method inferReturnType.
public void inferReturnType(IType type, IType valueType) {
if (this.hasImplicitReturnType()) {
this.returnType = valueType;
}
if ((this.flags & LAMBDA_TYPE_INFERRED) != 0 || type.canExtract(LambdaType.class)) {
this.type = this.makeType();
return;
}
final ITypeContext tempContext = new MapTypeContext();
final ParameterList methodParams = this.method.getParameters();
final int size = Math.min(this.parameters.size(), methodParams.size());
for (int i = 0; i < size; i++) {
final IParameter lambdaParam = this.parameters.get(i);
final IParameter methodParam = methodParams.get(i);
methodParam.getType().inferTypes(lambdaParam.getType(), tempContext);
}
this.method.getType().inferTypes(valueType, tempContext);
final IType classType = this.method.getEnclosingClass().getThisType();
this.type = classType.getConcreteType(tempContext);
}
use of dyvilx.tools.compiler.ast.generic.ITypeContext in project Dyvil by Dyvil.
the class CodeMethod method checkOverrideMethods.
private void checkOverrideMethods(MarkerList markers) {
if (this.checkNoOverride(markers)) {
return;
}
final ITypeContext typeContext = this.enclosingClass.getThisType();
this.filterOverrides(markers, typeContext);
if (this.checkNoOverride(markers)) {
return;
}
if (!this.isOverride() && !this.attributes.hasFlag(Modifiers.GENERATED)) {
markers.add(Markers.semantic(this.position, "method.overrides", this.name));
}
final boolean thisTypeResolved = this.type.isResolved();
for (IMethod overrideMethod : this.overrideMethods) {
ModifierUtil.checkOverride(this, overrideMethod, markers);
if (!thisTypeResolved) {
continue;
}
final IType superReturnType = overrideMethod.getType().getConcreteType(typeContext);
if (// avoid extra error
superReturnType != this.type && superReturnType.isResolved() && !Types.isSuperType(superReturnType.asParameterType(), this.type)) {
final Marker marker = Markers.semanticError(this.position, "method.override.type.incompatible", this.name);
marker.addInfo(Markers.getSemantic("method.type", this.type));
marker.addInfo(Markers.getSemantic("method.override.type", superReturnType));
addOverrideInfo(typeContext, overrideMethod, marker);
markers.add(marker);
}
}
}
use of dyvilx.tools.compiler.ast.generic.ITypeContext in project Dyvil by Dyvil.
the class IDataMember method checkAssign.
default IValue checkAssign(MarkerList markers, IContext context, SourcePosition position, IValue receiver, IValue newValue) {
if (this.hasModifier(Modifiers.FINAL) && !context.isConstructor()) {
markers.add(Markers.semanticError(position, this.getKind().getName() + ".assign.final", this.getName()));
}
final IType type = this.getType();
final ITypeContext typeContext = receiver == null ? ITypeContext.NULL : receiver.getType();
final TypeChecker.MarkerSupplier markerSupplier = (errorPosition, expected, actual) -> {
final String kindName = this.getKind().getName();
final Marker marker = Markers.semanticError(errorPosition, kindName + ".assign.type", this.getName());
marker.addInfo(Markers.getSemantic(kindName + ".type", expected));
marker.addInfo(Markers.getSemantic("value.type", actual));
return marker;
};
return TypeChecker.convertValue(newValue, type, typeContext, markers, context, markerSupplier);
}
Aggregations