Search in sources :

Example 1 with Markers

use of dyvilx.tools.compiler.util.Markers in project Dyvil by Dyvil.

the class NamedGenericType method checkCount.

private IType checkCount(MarkerList markers, ITypeParametric generic, String kind, IType type) {
    final int genericArity = generic.typeArity();
    if (genericArity <= 0) {
        markers.add(Markers.semanticError(this.position, "type.generic." + kind + ".not_generic", type));
        return type.atPosition(this.position);
    }
    if (genericArity != this.arguments.size()) {
        final Marker marker = Markers.semanticError(this.position, "type.generic." + kind + ".count_mismatch", type);
        marker.addInfo(Markers.getSemantic("type.generic.argument_count", this.arguments.size()));
        marker.addInfo(Markers.getSemantic("type.generic.parameter_count", genericArity));
        markers.add(marker);
    }
    return type.getConcreteType(typeParameter -> this.arguments.get(typeParameter.getIndex())).atPosition(this.position);
}
Also used : DataOutput(java.io.DataOutput) IContext(dyvilx.tools.compiler.ast.context.IContext) Package(dyvilx.tools.compiler.ast.structure.Package) Name(dyvil.lang.Name) ResolvedTypeVarType(dyvilx.tools.compiler.ast.type.typevar.ResolvedTypeVarType) IType(dyvilx.tools.compiler.ast.type.IType) IOException(java.io.IOException) Types(dyvilx.tools.compiler.ast.type.builtin.Types) PackageType(dyvilx.tools.compiler.ast.type.raw.PackageType) Marker(dyvilx.tools.parsing.marker.Marker) ITypeAlias(dyvilx.tools.compiler.ast.type.alias.ITypeAlias) ITypeParametric(dyvilx.tools.compiler.ast.generic.ITypeParametric) Markers(dyvilx.tools.compiler.util.Markers) SourcePosition(dyvil.source.position.SourcePosition) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) TypeList(dyvilx.tools.compiler.ast.type.TypeList) MarkerList(dyvilx.tools.parsing.marker.MarkerList) DataInput(java.io.DataInput) MatchList(dyvilx.tools.compiler.ast.method.MatchList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IUnresolvedType(dyvilx.tools.compiler.ast.type.raw.IUnresolvedType) Marker(dyvilx.tools.parsing.marker.Marker)

Example 2 with Markers

use of dyvilx.tools.compiler.util.Markers 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);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IValueConsumer(dyvilx.tools.compiler.ast.consumer.IValueConsumer) IContext(dyvilx.tools.compiler.ast.context.IContext) TypeChecker(dyvilx.tools.compiler.transform.TypeChecker) IType(dyvilx.tools.compiler.ast.type.IType) MemberKind(dyvilx.tools.compiler.ast.member.MemberKind) WriteableExpression(dyvilx.tools.compiler.ast.expression.WriteableExpression) IMember(dyvilx.tools.compiler.ast.member.IMember) Types(dyvilx.tools.compiler.ast.type.builtin.Types) Formatting(dyvilx.tools.compiler.config.Formatting) Marker(dyvilx.tools.parsing.marker.Marker) SourcePosition(dyvil.source.position.SourcePosition) Markers(dyvilx.tools.compiler.util.Markers) BytecodeException(dyvilx.tools.compiler.backend.exception.BytecodeException) MarkerList(dyvilx.tools.parsing.marker.MarkerList) NonNull(dyvil.annotation.internal.NonNull) Modifiers(dyvil.reflect.Modifiers) MethodWriter(dyvilx.tools.compiler.backend.MethodWriter) IClass(dyvilx.tools.compiler.ast.classes.IClass) TypeChecker(dyvilx.tools.compiler.transform.TypeChecker) Marker(dyvilx.tools.parsing.marker.Marker) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

SourcePosition (dyvil.source.position.SourcePosition)2 IClass (dyvilx.tools.compiler.ast.classes.IClass)2 IContext (dyvilx.tools.compiler.ast.context.IContext)2 IType (dyvilx.tools.compiler.ast.type.IType)2 Types (dyvilx.tools.compiler.ast.type.builtin.Types)2 Markers (dyvilx.tools.compiler.util.Markers)2 Marker (dyvilx.tools.parsing.marker.Marker)2 MarkerList (dyvilx.tools.parsing.marker.MarkerList)2 NonNull (dyvil.annotation.internal.NonNull)1 Name (dyvil.lang.Name)1 Modifiers (dyvil.reflect.Modifiers)1 IValueConsumer (dyvilx.tools.compiler.ast.consumer.IValueConsumer)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 WriteableExpression (dyvilx.tools.compiler.ast.expression.WriteableExpression)1 ITypeContext (dyvilx.tools.compiler.ast.generic.ITypeContext)1 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)1 ITypeParametric (dyvilx.tools.compiler.ast.generic.ITypeParametric)1 IMember (dyvilx.tools.compiler.ast.member.IMember)1 MemberKind (dyvilx.tools.compiler.ast.member.MemberKind)1 MatchList (dyvilx.tools.compiler.ast.method.MatchList)1