Search in sources :

Example 1 with Wildcard

use of org.eclipse.n4js.ts.typeRefs.Wildcard in project n4js by eclipse.

the class Reducer method reduceConstraintForTypeArgumentPair.

/**
 * Will add a constraint ⟨ leftArg :> rightArg ⟩, taking into account wildcards, closed existential types, and
 * definition site variance.
 */
private boolean reduceConstraintForTypeArgumentPair(TypeArgument leftArg, TypeVariable leftParam, TypeArgument rightArg) {
    boolean wasAdded = false;
    if (leftArg instanceof Wildcard) {
        final TypeRef ub = ((Wildcard) leftArg).getDeclaredUpperBound();
        if (ub != null) {
            wasAdded |= reduce(ub, ts.upperBound(G, rightArg).getValue(), CONTRA);
        }
        final TypeRef lb = ((Wildcard) leftArg).getDeclaredLowerBound();
        if (lb != null) {
            wasAdded |= reduce(lb, ts.lowerBound(G, rightArg).getValue(), CO);
        }
    } else if (rightArg instanceof ExistentialTypeRef) {
        // TODO IDE-1653 reconsider this entire case
        // re-open the existential type, because we assume it was closed only while adding substitutions
        // UPDATE: this is wrong if right.typeArgs already contained an ExistentialTypeRef! (but might be
        // an non-harmful over approximation)
        final Wildcard w = ((ExistentialTypeRef) rightArg).getWildcard();
        final TypeRef ub = w.getDeclaredUpperBound();
        if (ub != null) {
            wasAdded |= reduce(ub, ts.upperBound(G, leftArg).getValue(), CONTRA);
        }
        final TypeRef lb = w.getDeclaredLowerBound();
        if (lb != null) {
            wasAdded |= reduce(lb, ts.lowerBound(G, leftArg).getValue(), CO);
        }
    } else {
        if (!(leftArg instanceof TypeRef)) {
            throw new UnsupportedOperationException("unsupported subtype of TypeArgument: " + leftArg.getClass().getName());
        }
        // due to the assumption of the method, we always have: leftArg :> rightArg
        // (so for def-site variance we just look at the left side in this case, i.e. leftParam)
        final Variance leftDefSiteVarianceRaw = leftParam.getVariance();
        final Variance leftDefSiteVariance = leftDefSiteVarianceRaw != null ? leftDefSiteVarianceRaw : INV;
        wasAdded |= reduce(leftArg, rightArg, CONTRA.mult(leftDefSiteVariance));
    }
    return wasAdded;
}
Also used : ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) Wildcard(org.eclipse.n4js.ts.typeRefs.Wildcard) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) Variance(org.eclipse.n4js.ts.types.util.Variance)

Example 2 with Wildcard

use of org.eclipse.n4js.ts.typeRefs.Wildcard in project n4js by eclipse.

the class InternalTypeSystem method applyRuleUpperBoundExistentialTypeRef.

protected Result<TypeRef> applyRuleUpperBoundExistentialTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ExistentialTypeRef existentialTypeRef) throws RuleFailedException {
    // output parameter
    TypeRef T = null;
    /* G |~ existentialTypeRef.wildcard /\ T */
    Wildcard _wildcard = existentialTypeRef.getWildcard();
    Result<TypeRef> result = upperBoundInternal(G, _trace_, _wildcard);
    checkAssignableTo(result.getFirst(), TypeRef.class);
    T = (TypeRef) result.getFirst();
    T = TypeUtils.<TypeRef>copy(T);
    TypeUtils.copyTypeModifiers(T, existentialTypeRef);
    return new Result<TypeRef>(T);
}
Also used : Wildcard(org.eclipse.n4js.ts.typeRefs.Wildcard) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 3 with Wildcard

use of org.eclipse.n4js.ts.typeRefs.Wildcard in project n4js by eclipse.

the class InternalTypeSystem method applyRuleSubtypeTypeTypeRef.

protected Result<Boolean> applyRuleSubtypeTypeTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final TypeTypeRef left, final TypeTypeRef right) throws RuleFailedException {
    final TypeArgument leftTypeArg = left.getTypeArg();
    final TypeArgument rightTypeArg = right.getTypeArg();
    final boolean leftIsCtorRef = left.isConstructorRef();
    final boolean rightIsCtorRef = right.isConstructorRef();
    final boolean rightHasTypeRef = (rightTypeArg instanceof TypeRef);
    if (((!leftIsCtorRef) && rightIsCtorRef)) {
        /* fail */
        throwForExplicitFail();
    } else {
        if ((rightHasTypeRef && (!rightIsCtorRef))) {
            /* G |- leftTypeArg <: rightTypeArg */
            subtypeInternal(G, _trace_, leftTypeArg, rightTypeArg);
        } else {
            if ((rightHasTypeRef && rightIsCtorRef)) {
                final Type left_staticType = this.typeSystemHelper.getStaticType(G, left);
                final Type right_staticType = this.typeSystemHelper.getStaticType(G, right);
                final boolean leftHasCovariantConstructor = ((left_staticType instanceof TClassifier) && N4JSLanguageUtils.hasCovariantConstructor(((TClassifier) left_staticType)));
                /* !(leftTypeArg instanceof Wildcard || leftTypeArg instanceof ExistentialTypeRef || leftTypeArg instanceof ThisTypeRef) || leftHasCovariantConstructor */
                if (!((!(((leftTypeArg instanceof Wildcard) || (leftTypeArg instanceof ExistentialTypeRef)) || (leftTypeArg instanceof ThisTypeRef))) || leftHasCovariantConstructor)) {
                    sneakyThrowRuleFailedException("!(leftTypeArg instanceof Wildcard || leftTypeArg instanceof ExistentialTypeRef || leftTypeArg instanceof ThisTypeRef) || leftHasCovariantConstructor");
                }
                /* G |- leftTypeArg <: rightTypeArg */
                subtypeInternal(G, _trace_, leftTypeArg, rightTypeArg);
                if (((left_staticType instanceof TypeVariable) || (right_staticType instanceof TypeVariable))) {
                    /* left_staticType === right_staticType */
                    if (!(left_staticType == right_staticType)) {
                        sneakyThrowRuleFailedException("left_staticType === right_staticType");
                    }
                } else {
                    final TMethod leftCtor = this.containerTypesHelper.fromContext(RuleEnvironmentExtensions.getContextResource(G)).findConstructor(((ContainerType<?>) left_staticType));
                    final TMethod rightCtor = this.containerTypesHelper.fromContext(RuleEnvironmentExtensions.getContextResource(G)).findConstructor(((ContainerType<?>) right_staticType));
                    /* leftCtor!==null && rightCtor!==null */
                    if (!((leftCtor != null) && (rightCtor != null))) {
                        sneakyThrowRuleFailedException("leftCtor!==null && rightCtor!==null");
                    }
                    /* G |- leftCtor : var TypeRef leftCtorRef */
                    TypeRef leftCtorRef = null;
                    Result<TypeRef> result = typeInternal(G, _trace_, leftCtor);
                    checkAssignableTo(result.getFirst(), TypeRef.class);
                    leftCtorRef = (TypeRef) result.getFirst();
                    /* G |- rightCtor : var TypeRef rightCtorRef */
                    TypeRef rightCtorRef = null;
                    Result<TypeRef> result_1 = typeInternal(G, _trace_, rightCtor);
                    checkAssignableTo(result_1.getFirst(), TypeRef.class);
                    rightCtorRef = (TypeRef) result_1.getFirst();
                    final RuleEnvironment G_left = RuleEnvironmentExtensions.wrap(G);
                    final RuleEnvironment G_right = RuleEnvironmentExtensions.wrap(G);
                    this.typeSystemHelper.addSubstitutions(G_left, TypeExtensions.ref(left_staticType));
                    RuleEnvironmentExtensions.addThisType(G_left, TypeExtensions.ref(left_staticType));
                    this.typeSystemHelper.addSubstitutions(G_right, TypeExtensions.ref(right_staticType));
                    RuleEnvironmentExtensions.addThisType(G_right, TypeExtensions.ref(right_staticType));
                    /* G_left |- leftCtorRef ~> var TypeRef leftCtorRefSubst */
                    TypeRef leftCtorRefSubst = null;
                    Result<TypeArgument> result_2 = substTypeVariablesInternal(G_left, _trace_, leftCtorRef);
                    checkAssignableTo(result_2.getFirst(), TypeRef.class);
                    leftCtorRefSubst = (TypeRef) result_2.getFirst();
                    /* G_right |- rightCtorRef ~> var TypeRef rightCtorRefSubst */
                    TypeRef rightCtorRefSubst = null;
                    Result<TypeArgument> result_3 = substTypeVariablesInternal(G_right, _trace_, rightCtorRef);
                    checkAssignableTo(result_3.getFirst(), TypeRef.class);
                    rightCtorRefSubst = (TypeRef) result_3.getFirst();
                    /* G |- leftCtorRefSubst <: rightCtorRefSubst */
                    subtypeInternal(G, _trace_, leftCtorRefSubst, rightCtorRefSubst);
                }
            } else {
                /* G |~ leftTypeArg /\ var TypeRef upperBoundLeft */
                TypeRef upperBoundLeft = null;
                Result<TypeRef> result_4 = upperBoundInternal(G, _trace_, leftTypeArg);
                checkAssignableTo(result_4.getFirst(), TypeRef.class);
                upperBoundLeft = (TypeRef) result_4.getFirst();
                /* G |~ leftTypeArg \/ var TypeRef lowerBoundLeft */
                TypeRef lowerBoundLeft = null;
                Result<TypeRef> result_5 = lowerBoundInternal(G, _trace_, leftTypeArg);
                checkAssignableTo(result_5.getFirst(), TypeRef.class);
                lowerBoundLeft = (TypeRef) result_5.getFirst();
                /* G |~ rightTypeArg /\ var TypeRef upperBoundRight */
                TypeRef upperBoundRight = null;
                Result<TypeRef> result_6 = upperBoundInternal(G, _trace_, rightTypeArg);
                checkAssignableTo(result_6.getFirst(), TypeRef.class);
                upperBoundRight = (TypeRef) result_6.getFirst();
                /* G |~ rightTypeArg \/ var TypeRef lowerBoundRight */
                TypeRef lowerBoundRight = null;
                Result<TypeRef> result_7 = lowerBoundInternal(G, _trace_, rightTypeArg);
                checkAssignableTo(result_7.getFirst(), TypeRef.class);
                lowerBoundRight = (TypeRef) result_7.getFirst();
                /* G |- upperBoundLeft <: upperBoundRight */
                subtypeInternal(G, _trace_, upperBoundLeft, upperBoundRight);
                /* G |- lowerBoundRight <: lowerBoundLeft */
                subtypeInternal(G, _trace_, lowerBoundRight, lowerBoundLeft);
            }
        }
    }
    return new Result<Boolean>(true);
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) TMethod(org.eclipse.n4js.ts.types.TMethod) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) Wildcard(org.eclipse.n4js.ts.typeRefs.Wildcard) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment)

Example 4 with Wildcard

use of org.eclipse.n4js.ts.typeRefs.Wildcard in project n4js by eclipse.

the class InternalTypeSystem method applyRuleSubstTypeVariablesWildcard.

protected Result<TypeArgument> applyRuleSubstTypeVariablesWildcard(final RuleEnvironment G, final RuleApplicationTrace _trace_, final Wildcard wildcard) throws RuleFailedException {
    // output parameter
    Wildcard T = null;
    TypeRef ub = wildcard.getDeclaredUpperBound();
    if ((ub != null)) {
        /* G |- ub ~> ub */
        Result<TypeArgument> result = substTypeVariablesInternal(G, _trace_, ub);
        checkAssignableTo(result.getFirst(), TypeRef.class);
        ub = (TypeRef) result.getFirst();
    }
    TypeRef lb = wildcard.getDeclaredLowerBound();
    if ((lb != null)) {
        /* G |- lb ~> lb */
        Result<TypeArgument> result_1 = substTypeVariablesInternal(G, _trace_, lb);
        checkAssignableTo(result_1.getFirst(), TypeRef.class);
        lb = (TypeRef) result_1.getFirst();
    }
    if (((ub != wildcard.getDeclaredUpperBound()) || (lb != wildcard.getDeclaredLowerBound()))) {
        T = TypeUtils.<Wildcard>copy(wildcard);
        T.setDeclaredUpperBound(TypeUtils.<TypeRef>copyIfContained(ub));
        T.setDeclaredLowerBound(TypeUtils.<TypeRef>copyIfContained(lb));
    } else {
        T = wildcard;
    }
    return new Result<TypeArgument>(T);
}
Also used : Wildcard(org.eclipse.n4js.ts.typeRefs.Wildcard) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult)

Example 5 with Wildcard

use of org.eclipse.n4js.ts.typeRefs.Wildcard in project n4js by eclipse.

the class InternalTypeSystem method applyRuleSubtypeParameterizedTypeRef.

protected Result<Boolean> applyRuleSubtypeParameterizedTypeRef(final RuleEnvironment G, final RuleApplicationTrace _trace_, final ParameterizedTypeRef leftOriginal, final ParameterizedTypeRef rightOriginal) throws RuleFailedException {
    final TypeRef left = RuleEnvironmentExtensions.getReplacement(G, leftOriginal);
    final TypeRef right = RuleEnvironmentExtensions.getReplacement(G, rightOriginal);
    final Type leftDeclType = left.getDeclaredType();
    final Type rightDeclType = right.getDeclaredType();
    if (((leftDeclType == null) || (rightDeclType == null))) {
        /* true */
        if (!true) {
            sneakyThrowRuleFailedException("true");
        }
    } else {
        if ((leftDeclType.eIsProxy() || rightDeclType.eIsProxy())) {
            /* true */
            if (!true) {
                sneakyThrowRuleFailedException("true");
            }
        } else {
            if (((leftDeclType instanceof VoidType) || (rightDeclType instanceof VoidType))) {
                /* leftDeclType instanceof VoidType && rightDeclType instanceof VoidType */
                if (!((leftDeclType instanceof VoidType) && (rightDeclType instanceof VoidType))) {
                    sneakyThrowRuleFailedException("leftDeclType instanceof VoidType && rightDeclType instanceof VoidType");
                }
            } else {
                if ((((leftDeclType instanceof UndefinedType) || ((leftDeclType instanceof NullType) && (!(rightDeclType instanceof UndefinedType)))) || (rightDeclType instanceof AnyType))) {
                    /* true */
                    if (!true) {
                        sneakyThrowRuleFailedException("true");
                    }
                } else {
                    if ((((leftDeclType == RuleEnvironmentExtensions.intType(G)) && (rightDeclType == RuleEnvironmentExtensions.numberType(G))) || ((leftDeclType == RuleEnvironmentExtensions.numberType(G)) && (rightDeclType == RuleEnvironmentExtensions.intType(G))))) {
                        /* true */
                        if (!true) {
                            sneakyThrowRuleFailedException("true");
                        }
                    } else {
                        if (((leftDeclType instanceof TEnum) && ((rightDeclType == RuleEnvironmentExtensions.n4EnumType(G)) || (rightDeclType == RuleEnvironmentExtensions.objectType(G))))) {
                            boolean _hasAnnotation = AnnotationDefinition.STRING_BASED.hasAnnotation(leftDeclType);
                            /* !AnnotationDefinition.STRING_BASED.hasAnnotation( leftDeclType ) */
                            if (!(!_hasAnnotation)) {
                                sneakyThrowRuleFailedException("!AnnotationDefinition.STRING_BASED.hasAnnotation( leftDeclType )");
                            }
                        } else {
                            if (((leftDeclType instanceof TEnum) && (((rightDeclType == RuleEnvironmentExtensions.n4StringBasedEnumType(G)) || (rightDeclType == RuleEnvironmentExtensions.stringType(G))) || (rightDeclType == RuleEnvironmentExtensions.stringObjectType(G))))) {
                                /* AnnotationDefinition.STRING_BASED.hasAnnotation( leftDeclType ) */
                                if (!AnnotationDefinition.STRING_BASED.hasAnnotation(leftDeclType)) {
                                    sneakyThrowRuleFailedException("AnnotationDefinition.STRING_BASED.hasAnnotation( leftDeclType )");
                                }
                            } else {
                                if (((leftDeclType == RuleEnvironmentExtensions.n4StringBasedEnumType(G)) && ((rightDeclType == RuleEnvironmentExtensions.stringType(G)) || (rightDeclType == RuleEnvironmentExtensions.stringObjectType(G))))) {
                                    /* true */
                                    if (!true) {
                                        sneakyThrowRuleFailedException("true");
                                    }
                                } else {
                                    if (((leftDeclType instanceof PrimitiveType) && (((PrimitiveType) leftDeclType).getAssignmentCompatible() == rightDeclType))) {
                                        /* true */
                                        if (!true) {
                                            sneakyThrowRuleFailedException("true");
                                        }
                                    } else {
                                        if (((rightDeclType instanceof PrimitiveType) && (leftDeclType == ((PrimitiveType) rightDeclType).getAssignmentCompatible()))) {
                                            /* true */
                                            if (!true) {
                                                sneakyThrowRuleFailedException("true");
                                            }
                                        } else {
                                            if (((((leftDeclType instanceof TInterface) && (!(rightDeclType instanceof TInterface))) && Objects.equal(right.getTypingStrategy(), TypingStrategy.NOMINAL)) && (!(((rightDeclType == RuleEnvironmentExtensions.n4ObjectType(G)) || (rightDeclType == RuleEnvironmentExtensions.objectType(G))) || (rightDeclType == RuleEnvironmentExtensions.anyType(G)))))) {
                                                /* false */
                                                if (!false) {
                                                    sneakyThrowRuleFailedException("false");
                                                }
                                            } else {
                                                boolean structuralTyping = false;
                                                boolean _isUseSiteStructuralTyping = right.isUseSiteStructuralTyping();
                                                if (_isUseSiteStructuralTyping) {
                                                    final StructuralTypingResult result = this.typeSystemHelper.isStructuralSubtype(G, left, right);
                                                    boolean _isValue = result.isValue();
                                                    boolean _not = (!_isValue);
                                                    if (_not) {
                                                        /* fail error result.message data PRIORITY_ERROR */
                                                        String _message = result.getMessage();
                                                        String error = _message;
                                                        Object data = TypeSystemErrorExtensions.PRIORITY_ERROR;
                                                        throwForExplicitFail(error, new ErrorInformation(null, null, data));
                                                    }
                                                    structuralTyping = true;
                                                } else {
                                                    boolean _isDefSiteStructuralTyping = right.isDefSiteStructuralTyping();
                                                    if (_isDefSiteStructuralTyping) {
                                                        Pair<TypeRef, TypeRef> _mappedTo = Pair.<TypeRef, TypeRef>of(left, right);
                                                        Pair<String, Pair<TypeRef, TypeRef>> _mappedTo_1 = Pair.<String, Pair<TypeRef, TypeRef>>of(RuleEnvironmentExtensions.GUARD_SUBTYPE_PARAMETERIZED_TYPE_REF__STRUCT, _mappedTo);
                                                        Object _get = G.get(_mappedTo_1);
                                                        final Boolean guard = ((Boolean) _get);
                                                        if (((guard == null) || (!(guard).booleanValue()))) {
                                                            final StructuralTypingResult result_1 = this.typeSystemHelper.isStructuralSubtype(G, left, right);
                                                            boolean _isValue_1 = result_1.isValue();
                                                            boolean _not_1 = (!_isValue_1);
                                                            if (_not_1) {
                                                                boolean _and = false;
                                                                boolean _isN4ObjectOnLeftWithDefSite = result_1.isN4ObjectOnLeftWithDefSite();
                                                                if (!_isN4ObjectOnLeftWithDefSite) {
                                                                    _and = false;
                                                                } else {
                                                                    /* G.wrap, (GUARD_SUBTYPE_PARAMETERIZED_TYPE_REF__STRUCT->(left->right))<-true |- left <: right */
                                                                    RuleEnvironment _wrap = RuleEnvironmentExtensions.wrap(G);
                                                                    Pair<TypeRef, TypeRef> _mappedTo_2 = Pair.<TypeRef, TypeRef>of(left, right);
                                                                    Pair<String, Pair<TypeRef, TypeRef>> _mappedTo_3 = Pair.<String, Pair<TypeRef, TypeRef>>of(RuleEnvironmentExtensions.GUARD_SUBTYPE_PARAMETERIZED_TYPE_REF__STRUCT, _mappedTo_2);
                                                                    boolean _ruleinvocation = subtypeSucceeded(environmentComposition(_wrap, environmentEntry(_mappedTo_3, true)), _trace_, left, right);
                                                                    _and = _ruleinvocation;
                                                                }
                                                                if (_and) {
                                                                    structuralTyping = true;
                                                                } else {
                                                                    /* fail error result.message data PRIORITY_ERROR */
                                                                    String _message_1 = result_1.getMessage();
                                                                    String error_1 = _message_1;
                                                                    Object data_1 = TypeSystemErrorExtensions.PRIORITY_ERROR;
                                                                    throwForExplicitFail(error_1, new ErrorInformation(null, null, data_1));
                                                                }
                                                            }
                                                            structuralTyping = result_1.isValue();
                                                        }
                                                    }
                                                }
                                                if ((!structuralTyping)) {
                                                    if ((((left.isUseSiteStructuralTyping() || left.isDefSiteStructuralTyping()) && (!(Objects.equal(rightDeclType, RuleEnvironmentExtensions.objectType(G)) && (leftDeclType instanceof TClassifier)))) && (!(leftDeclType instanceof PrimitiveType)))) {
                                                        /* fail error "Structural type " + left.typeRefAsString + " is not a subtype of non-structural type " + right.typeRefAsString data PRIORITY_ERROR */
                                                        String _typeRefAsString = left.getTypeRefAsString();
                                                        String _plus = ("Structural type " + _typeRefAsString);
                                                        String _plus_1 = (_plus + " is not a subtype of non-structural type ");
                                                        String _typeRefAsString_1 = right.getTypeRefAsString();
                                                        String _plus_2 = (_plus_1 + _typeRefAsString_1);
                                                        String error_2 = _plus_2;
                                                        Object data_2 = TypeSystemErrorExtensions.PRIORITY_ERROR;
                                                        throwForExplicitFail(error_2, new ErrorInformation(null, null, data_2));
                                                    }
                                                    if (((leftDeclType instanceof TypeVariable) || (rightDeclType instanceof TypeVariable))) {
                                                        boolean _equals = Objects.equal(leftDeclType, rightDeclType);
                                                        if (_equals) {
                                                            /* true */
                                                            if (!true) {
                                                                sneakyThrowRuleFailedException("true");
                                                            }
                                                        } else {
                                                            if ((leftDeclType instanceof TypeVariable)) {
                                                                TypeRef _elvis = null;
                                                                TypeRef _declaredUpperBound = ((TypeVariable) leftDeclType).getDeclaredUpperBound();
                                                                if (_declaredUpperBound != null) {
                                                                    _elvis = _declaredUpperBound;
                                                                } else {
                                                                    TypeRef _typeVariableImplicitUpperBound = N4JSLanguageUtils.getTypeVariableImplicitUpperBound(G);
                                                                    _elvis = _typeVariableImplicitUpperBound;
                                                                }
                                                                final TypeRef ub = _elvis;
                                                                /* G |- ub <: right */
                                                                subtypeInternal(G, _trace_, ub, right);
                                                            } else {
                                                                /* false */
                                                                if (!false) {
                                                                    sneakyThrowRuleFailedException("false");
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        boolean _equals_1 = Objects.equal(leftDeclType, rightDeclType);
                                                        if (_equals_1) {
                                                            if (((left.getTypeArgs().size() > 0) && (left.getTypeArgs().size() <= right.getTypeArgs().size()))) {
                                                                final int len = Math.min(Math.min(left.getTypeArgs().size(), right.getTypeArgs().size()), rightDeclType.getTypeVars().size());
                                                                for (int i = 0; (i < len); i++) {
                                                                    final TypeArgument leftArg = left.getTypeArgs().get(i);
                                                                    final TypeArgument rightArg = right.getTypeArgs().get(i);
                                                                    final Variance variance = rightDeclType.getVarianceOfTypeVar(i);
                                                                    TypeRef leftArgUpper = null;
                                                                    /* G |~ leftArg /\ leftArgUpper */
                                                                    Result<TypeRef> result_2 = upperBoundInternal(G, _trace_, leftArg);
                                                                    checkAssignableTo(result_2.getFirst(), TypeRef.class);
                                                                    leftArgUpper = (TypeRef) result_2.getFirst();
                                                                    TypeRef leftArgLower = null;
                                                                    /* G |~ leftArg \/ leftArgLower */
                                                                    Result<TypeRef> result_3 = lowerBoundInternal(G, _trace_, leftArg);
                                                                    checkAssignableTo(result_3.getFirst(), TypeRef.class);
                                                                    leftArgLower = (TypeRef) result_3.getFirst();
                                                                    TypeRef rightArgUpper = null;
                                                                    /* G |~ rightArg /\ rightArgUpper */
                                                                    Result<TypeRef> result_4 = upperBoundInternal(G, _trace_, rightArg);
                                                                    checkAssignableTo(result_4.getFirst(), TypeRef.class);
                                                                    rightArgUpper = (TypeRef) result_4.getFirst();
                                                                    TypeRef rightArgLower = null;
                                                                    /* G |~ rightArg \/ rightArgLower */
                                                                    Result<TypeRef> result_5 = lowerBoundInternal(G, _trace_, rightArg);
                                                                    checkAssignableTo(result_5.getFirst(), TypeRef.class);
                                                                    rightArgLower = (TypeRef) result_5.getFirst();
                                                                    RuleEnvironment G2 = null;
                                                                    if (((rightArg instanceof Wildcard) && ((Wildcard) rightArg).isImplicitUpperBoundInEffect())) {
                                                                        Pair<String, TypeArgument> _mappedTo_4 = Pair.<String, TypeArgument>of(RuleEnvironmentExtensions.GUARD_SUBTYPE_PARAMETERIZED_TYPE_REF__ARGS, rightArg);
                                                                        Object _get_1 = G.get(_mappedTo_4);
                                                                        final boolean isGuarded = (_get_1 != null);
                                                                        if ((!isGuarded)) {
                                                                            G2 = RuleEnvironmentExtensions.wrap(G);
                                                                            Pair<String, TypeArgument> _mappedTo_5 = Pair.<String, TypeArgument>of(RuleEnvironmentExtensions.GUARD_SUBTYPE_PARAMETERIZED_TYPE_REF__ARGS, rightArg);
                                                                            /* G2.add(GUARD_SUBTYPE_PARAMETERIZED_TYPE_REF__ARGS->(rightArg), Boolean.TRUE) */
                                                                            if (!G2.add(_mappedTo_5, Boolean.TRUE)) {
                                                                                sneakyThrowRuleFailedException("G2.add(GUARD_SUBTYPE_PARAMETERIZED_TYPE_REF__ARGS->(rightArg), Boolean.TRUE)");
                                                                            }
                                                                        } else {
                                                                            rightArgUpper = RuleEnvironmentExtensions.topTypeRef(G);
                                                                            G2 = G;
                                                                        }
                                                                    } else {
                                                                        G2 = G;
                                                                    }
                                                                    /* { if(variance!=Variance.CONTRA) { G2 |- leftArgUpper <: rightArgUpper } if(variance!=Variance.CO) { G2 |- rightArgLower <: leftArgLower } } or { if(previousFailure.isOrCausedByPriorityError) { fail error stringRep(left) + " is not a subtype of " + stringRep(right) + " due to incompatible type arguments: " + previousFailure.compileMessage data PRIORITY_ERROR } else { fail } } */
                                                                    {
                                                                        RuleFailedException previousFailure = null;
                                                                        try {
                                                                            boolean _notEquals = (!Objects.equal(variance, Variance.CONTRA));
                                                                            if (_notEquals) {
                                                                                /* G2 |- leftArgUpper <: rightArgUpper */
                                                                                subtypeInternal(G2, _trace_, leftArgUpper, rightArgUpper);
                                                                            }
                                                                            boolean _notEquals_1 = (!Objects.equal(variance, Variance.CO));
                                                                            if (_notEquals_1) {
                                                                                /* G2 |- rightArgLower <: leftArgLower */
                                                                                subtypeInternal(G2, _trace_, rightArgLower, leftArgLower);
                                                                            }
                                                                        } catch (Exception e) {
                                                                            previousFailure = extractRuleFailedException(e);
                                                                            boolean _isOrCausedByPriorityError = TypeSystemErrorExtensions.isOrCausedByPriorityError(previousFailure);
                                                                            if (_isOrCausedByPriorityError) {
                                                                                /* fail error stringRep(left) + " is not a subtype of " + stringRep(right) + " due to incompatible type arguments: " + previousFailure.compileMessage data PRIORITY_ERROR */
                                                                                String _stringRep = this.stringRep(left);
                                                                                String _plus_3 = (_stringRep + " is not a subtype of ");
                                                                                String _stringRep_1 = this.stringRep(right);
                                                                                String _plus_4 = (_plus_3 + _stringRep_1);
                                                                                String _plus_5 = (_plus_4 + " due to incompatible type arguments: ");
                                                                                String _compileMessage = TypeSystemErrorExtensions.compileMessage(previousFailure);
                                                                                String _plus_6 = (_plus_5 + _compileMessage);
                                                                                String error_3 = _plus_6;
                                                                                Object data_3 = TypeSystemErrorExtensions.PRIORITY_ERROR;
                                                                                throwForExplicitFail(error_3, new ErrorInformation(null, null, data_3));
                                                                            } else {
                                                                                /* fail */
                                                                                throwForExplicitFail();
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        } else {
                                                            List<ParameterizedTypeRef> _xifexpression = null;
                                                            if ((leftDeclType instanceof ContainerType<?>)) {
                                                                _xifexpression = AllSuperTypeRefsCollector.collect(((ContainerType<?>) leftDeclType));
                                                            } else {
                                                                _xifexpression = CollectionLiterals.<ParameterizedTypeRef>newArrayList();
                                                            }
                                                            final List<ParameterizedTypeRef> allSuperTypeRefs = _xifexpression;
                                                            List<ParameterizedTypeRef> _collectAllImplicitSuperTypes = RuleEnvironmentExtensions.collectAllImplicitSuperTypes(G, left);
                                                            final Iterable<ParameterizedTypeRef> superTypeRefs = Iterables.<ParameterizedTypeRef>concat(allSuperTypeRefs, _collectAllImplicitSuperTypes);
                                                            final Function1<ParameterizedTypeRef, Boolean> _function = (ParameterizedTypeRef it) -> {
                                                                Type _declaredType = it.getDeclaredType();
                                                                return Boolean.valueOf((_declaredType == rightDeclType));
                                                            };
                                                            boolean _exists = IterableExtensions.<ParameterizedTypeRef>exists(superTypeRefs, _function);
                                                            if (_exists) {
                                                                final RuleEnvironment localG_left = RuleEnvironmentExtensions.wrap(G);
                                                                this.typeSystemHelper.addSubstitutions(localG_left, left);
                                                                final Function1<TypeVariable, TypeRef> _function_1 = (TypeVariable it) -> {
                                                                    return TypeExtensions.ref(it);
                                                                };
                                                                final TypeRef syntheticTypeRef = TypeExtensions.ref(rightDeclType, ((TypeArgument[]) Conversions.unwrapArray(ListExtensions.<TypeVariable, TypeRef>map(rightDeclType.getTypeVars(), _function_1), TypeArgument.class)));
                                                                /* localG_left |- syntheticTypeRef ~> var TypeRef effectiveSuperTypeRef */
                                                                TypeRef effectiveSuperTypeRef = null;
                                                                Result<TypeArgument> result_2 = substTypeVariablesInternal(localG_left, _trace_, syntheticTypeRef);
                                                                checkAssignableTo(result_2.getFirst(), TypeRef.class);
                                                                effectiveSuperTypeRef = (TypeRef) result_2.getFirst();
                                                                /* G |- effectiveSuperTypeRef <: right */
                                                                subtypeInternal(G, _trace_, effectiveSuperTypeRef, right);
                                                            } else {
                                                                /* false */
                                                                if (!false) {
                                                                    sneakyThrowRuleFailedException("false");
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return new Result<Boolean>(true);
}
Also used : VoidType(org.eclipse.n4js.ts.types.VoidType) TClassifier(org.eclipse.n4js.ts.types.TClassifier) TInterface(org.eclipse.n4js.ts.types.TInterface) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) StaticBaseTypeRef(org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) TaggedTemplateString(org.eclipse.n4js.n4JS.TaggedTemplateString) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) Variance(org.eclipse.n4js.ts.types.util.Variance) Result(org.eclipse.xsemantics.runtime.Result) StructuralTypingResult(org.eclipse.n4js.typesystem.StructuralTypingResult) ErrorInformation(org.eclipse.xsemantics.runtime.ErrorInformation) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) Wildcard(org.eclipse.n4js.ts.typeRefs.Wildcard) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) AnyType(org.eclipse.n4js.ts.types.AnyType) Pair(org.eclipse.xtext.xbase.lib.Pair) PropertyNameValuePair(org.eclipse.n4js.n4JS.PropertyNameValuePair) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument) RuleFailedException(org.eclipse.xsemantics.runtime.RuleFailedException) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) Type(org.eclipse.n4js.ts.types.Type) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) VoidType(org.eclipse.n4js.ts.types.VoidType) AnyType(org.eclipse.n4js.ts.types.AnyType) ModuleNamespaceVirtualType(org.eclipse.n4js.ts.types.ModuleNamespaceVirtualType) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType) ContainerType(org.eclipse.n4js.ts.types.ContainerType) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) TEnum(org.eclipse.n4js.ts.types.TEnum) EObject(org.eclipse.emf.ecore.EObject) NullType(org.eclipse.n4js.ts.types.NullType) UndefinedType(org.eclipse.n4js.ts.types.UndefinedType)

Aggregations

Wildcard (org.eclipse.n4js.ts.typeRefs.Wildcard)18 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)14 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)14 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)11 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)11 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)11 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)10 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)10 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)9 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)9 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)9 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)9 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)9 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)9 Result (org.eclipse.xsemantics.runtime.Result)9 FunctionTypeExpression (org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression)5 IntersectionTypeExpression (org.eclipse.n4js.ts.typeRefs.IntersectionTypeExpression)5 UnionTypeExpression (org.eclipse.n4js.ts.typeRefs.UnionTypeExpression)5 EPackage (org.eclipse.emf.ecore.EPackage)3 AdditiveExpression (org.eclipse.n4js.n4JS.AdditiveExpression)3