diff --git a/shared/typeinference/codeql/typeinference/internal/TypeInference.qll b/shared/typeinference/codeql/typeinference/internal/TypeInference.qll index 3c411d003920..f1577e7abc98 100644 --- a/shared/typeinference/codeql/typeinference/internal/TypeInference.qll +++ b/shared/typeinference/codeql/typeinference/internal/TypeInference.qll @@ -71,6 +71,57 @@ module; private import codeql.util.Location +private newtype TVariance = + TMkCovariant() or + TMkContravariant() + +/** Describes how a type parameter relates to its enclosing type. */ +class Variance extends TVariance { + predicate isCovariant() { this = TMkCovariant() } + + predicate isContravariant() { this = TMkContravariant() } + + string toString() { + this.isCovariant() and result = "covariant" + or + this.isContravariant() and result = "contravariant" + } +} + +private newtype TMatchingRelation = + TMkCovariantRelation() or + TMkContravariantRelation() or + TMkInvariantRelation() + +/** Describes the relation used while matching two type trees. */ +class MatchingRelation extends TMatchingRelation { + predicate isCovariant() { this = TMkCovariantRelation() } + + predicate isContravariant() { this = TMkContravariantRelation() } + + predicate isInvariant() { this = TMkInvariantRelation() } + + string toString() { + this.isCovariant() and result = "covariant" + or + this.isContravariant() and result = "contravariant" + or + this.isInvariant() and result = "invariant" + } + + MatchingRelation compose(Variance inner) { + this.isInvariant() and result.isInvariant() + or + this.isCovariant() and inner.isCovariant() and result.isCovariant() + or + this.isCovariant() and inner.isContravariant() and result.isContravariant() + or + this.isContravariant() and inner.isCovariant() and result.isContravariant() + or + this.isContravariant() and inner.isContravariant() and result.isCovariant() + } +} + /** Provides the input to `Make1`. */ signature module InputSig1 { /** @@ -105,6 +156,16 @@ signature module InputSig1 { /** A type parameter. */ class TypeParameter extends Type; + /** + * Gets the non-invariant variance of `tp`. An absent result means that the + * parameter is invariant. This describes the parameter's position in its + * constructor, not the variance of an inference variable substituted at that + * position. + * Clients with no variant parameters retain the existing non-recursive + * `typeMatch` behavior; `typeMatchBound` always uses recursive matching. + */ + default Variance getTypeParameterVariance(TypeParameter tp) { none() } + /** * A type abstraction. I.e., a place in the program where type variables may * be introduced. @@ -365,6 +426,10 @@ module Make1 Input1> { module Make2 Input2> { private import Input2 + private predicate varianceEnabled() { + exists(TypeParameter tp, Variance variance | variance = getTypeParameterVariance(tp)) + } + /** * Gets the non-pseudo root type mentioned at `tm`. * @@ -1200,6 +1265,288 @@ module Make1 Input1> { import SatisfiesConstraint } + /** Provides the relevant pairs of type trees for `VarianceMatching`. */ + signature module VarianceMatchingInputSig { + predicate relevantConstraint(Term term, Constraint constraint); + + /** Gets the initial relation between the matched type trees. */ + default MatchingRelation getRelation(Term term, Constraint constraint) { + relevantConstraint(term, constraint) and result.isCovariant() + } + + /** Gets an inferred instantiation for contextual propagation into `term`. */ + default Type getTypeArgument(Term term, Constraint constraint, TypeParameter tp, TypePath path) { + none() + } + } + + /** + * Recursively matches type trees, projecting subtrees through the nominal + * hierarchy only in the direction permitted by their enclosing parameters. + * Bounds are possible types, not solutions of a system of inequalities. + * Views are created only for relevant pairs, and their child/projection + * depth is bounded by `getTypePathLimit`, when configured. + */ + module VarianceMatching< + HasTypeTreeSig Term, HasTypeTreeSig Constraint, + VarianceMatchingInputSig Input> + { + private newtype TTree = + MkTerm(Term term) { Input::relevantConstraint(term, _) } or + MkConstraint(Constraint constraint) { Input::relevantConstraint(_, constraint) } or + MkChild(Tree parent, TypeParameter tp) { child(parent, tp) } or + MkBase(Tree tree, Type root) { projection(tree, root) } + + private class Tree extends TTree { + int getDepth() { + (this instanceof MkTerm or this instanceof MkConstraint) and + result = 0 + or + exists(Tree parent | + (this = MkChild(parent, _) or this = MkBase(parent, _)) and + result = parent.getDepth() + 1 + ) + } + + Type getTypeAt(TypePath path) { + exists(Term term | this = MkTerm(term) | result = term.getTypeAt(path)) + or + exists(Constraint constraint | this = MkConstraint(constraint) | + result = constraint.getTypeAt(path) + ) + or + exists(Tree parent, TypeParameter tp, TypePath parentPath | + this = MkChild(parent, tp) and + result = parent.getTypeAt(parentPath) and + parentPath.isCons(tp, path) + ) + or + exists(Tree parent, Type root | + this = MkBase(parent, root) and + Projection::satisfiesConstraint(parent, MkRoot(root), path, result) + ) + } + + /** Maps a projected path back to a path in the original term. */ + pragma[nomagic] + predicate originPath(TypePath path, TypePath original) { + relevantOrigin(this, path) and + ( + this instanceof MkTerm and original = path + or + exists(Tree parent, TypeParameter tp | + this = MkChild(parent, tp) and + parent.originPath(TypePath::cons(tp, path), original) + ) + or + exists(Tree parent, Type root, TypePath prefix, TypePath source, TypePath suffix | + this = MkBase(parent, root) and + Projection::satisfiesConstraintAtTypeParameter(parent, MkRoot(root), prefix, source) and + path = prefix.appendInverse(suffix) and + parent.originPath(source.append(suffix), original) + ) + ) + } + + string toString() { result = "variance matching subtree" } + + Location getLocation() { + exists(Term term | this = MkTerm(term) | result = term.getLocation()) + or + exists(Constraint constraint | this = MkConstraint(constraint) | + result = constraint.getLocation() + ) + or + exists(Tree parent | + (this = MkChild(parent, _) or this = MkBase(parent, _)) and + result = parent.getLocation() + ) + } + } + + private predicate canDescend(Tree tree) { + not exists(getTypePathLimit()) or tree.getDepth() < getTypePathLimit() + } + + private MatchingRelation childRelation(MatchingRelation relation, TypeParameter tp) { + not exists(Variance parameterVariance | parameterVariance = getTypeParameterVariance(tp)) and + result.isInvariant() + or + exists(Variance parameterVariance | + parameterVariance = getTypeParameterVariance(tp) and + result = relation.compose(parameterVariance) + ) + } + + pragma[nomagic] + private predicate aligned( + Term term, Constraint constraint, Tree actual, Tree expected, MatchingRelation relation + ) { + Input::relevantConstraint(term, constraint) and + actual = MkTerm(term) and + expected = MkConstraint(constraint) and + relation = Input::getRelation(term, constraint) + or + exists( + Tree actualParent, Tree expectedParent, MatchingRelation parentRelation, Type root, + TypeParameter tp + | + aligned(term, constraint, actualParent, expectedParent, parentRelation) and + root = actualParent.getTypeAt(TypePath::nil()) and + root = expectedParent.getTypeAt(TypePath::nil()) and + tp = root.getATypeParameter() and + canDescend(actualParent) and + canDescend(expectedParent) and + actual = MkChild(actualParent, tp) and + expected = MkChild(expectedParent, tp) and + relation = childRelation(parentRelation, tp) + ) + or + exists(Tree previous, Type root | + aligned(term, constraint, previous, expected, relation) and + relation.isCovariant() and + root = expected.getTypeAt(TypePath::nil()) and + projection(previous, root) and + actual = MkBase(previous, root) + ) + or + exists(Tree previous, Type root | + aligned(term, constraint, actual, previous, relation) and + relation.isContravariant() and + root = actual.getTypeAt(TypePath::nil()) and + projection(previous, root) and + expected = MkBase(previous, root) + ) + } + + private predicate child(Tree parent, TypeParameter tp) { + exists( + Term term, Constraint constraint, Tree actual, Tree expected, MatchingRelation relation, + Type root + | + aligned(term, constraint, actual, expected, relation) and + root = actual.getTypeAt(TypePath::nil()) and + root = expected.getTypeAt(TypePath::nil()) and + tp = root.getATypeParameter() and + (parent = actual or parent = expected) and + canDescend(actual) and + canDescend(expected) + ) + } + + private predicate projection(Tree tree, Type root) { + exists( + Term term, Constraint constraint, Tree actual, Tree expected, MatchingRelation relation, + Type source + | + aligned(term, constraint, actual, expected, relation) and + ( + relation.isCovariant() and tree = actual and root = expected.getTypeAt(TypePath::nil()) + or + relation.isContravariant() and + tree = expected and + root = actual.getTypeAt(TypePath::nil()) + ) and + source = tree.getTypeAt(TypePath::nil()) and + source != root and + rootTypesSatisfaction(source, root, _, _, _) and + canDescend(tree) + ) + } + + private newtype TRoot = MkRoot(Type root) { projection(_, root) } + + private class Root extends MkRoot { + Type root; + + Root() { this = MkRoot(root) } + + Type getTypeAt(TypePath path) { result = root and path.isEmpty() } + + string toString() { result = root.toString() } + + Location getLocation() { result = root.getLocation() } + } + + private module ProjectionInput implements SatisfiesConstraintInputSig { + predicate relevantConstraint(Tree term, Root constraint) { + exists(Type type | constraint = MkRoot(type) | projection(term, type)) + } + } + + private module Projection = SatisfiesConstraint; + + pragma[nomagic] + private predicate relevantOrigin(Tree tree, TypePath path) { + exists(Term term, Constraint constraint, Tree expected, MatchingRelation relation | + aligned(term, constraint, tree, expected, relation) and + tree.getTypeAt(TypePath::nil()) instanceof PseudoType and + ( + exists(expected.getTypeAt(path)) + or + exists(TypeParameter tp | + tp = expected.getTypeAt(TypePath::nil()) and + exists(Input::getTypeArgument(term, constraint, tp, path)) + ) + ) + ) + or + exists(Tree child, TypeParameter tp, TypePath suffix | + relevantOrigin(child, suffix) and + child = MkChild(tree, tp) and + path = TypePath::cons(tp, suffix) + ) + or + exists( + Tree base, Type root, TypePath prefix, TypePath source, TypePath suffix, TypePath basePath + | + relevantOrigin(base, basePath) and + base = MkBase(tree, root) and + Projection::satisfiesConstraintAtTypeParameter(tree, MkRoot(root), prefix, source) and + basePath = prefix.appendInverse(suffix) and + path = source.append(suffix) + ) + } + + /** + * Gets a possible bound on `tp`. Covariance denotes a lower bound + * (`t <: tp`), contravariance an upper bound (`tp <: t`), and invariance + * equality. All paths in a bound refer to the same projected subtree. + */ + pragma[nomagic] + predicate typeBound( + Term term, Constraint constraint, TypeParameter tp, MatchingRelation relation, + TypePath path, Type t + ) { + exists(Tree actual, Tree expected | + aligned(term, constraint, actual, expected, relation) and + tp = expected.getTypeAt(TypePath::nil()) and + tp = constraint.getTypeAt(_) and + t = actual.getTypeAt(path) + ) + } + + /** Gets a contextual type for an unknown subtree of the original term. */ + pragma[nomagic] + Type contextualType(Term term, Constraint constraint, TypePath path) { + exists(Tree actual, Tree expected, MatchingRelation relation, TypePath suffix | + aligned(term, constraint, actual, expected, relation) and + actual.getTypeAt(TypePath::nil()) instanceof PseudoType and + ( + result = expected.getTypeAt(suffix) + or + exists(TypeParameter tp | + tp = expected.getTypeAt(TypePath::nil()) and + result = Input::getTypeArgument(term, constraint, tp, suffix) + ) + ) and + not result instanceof TypeParameter and + not result instanceof PseudoType and + actual.originPath(suffix, path) + ) + } + } + /** Provides the input to `MatchingWithEnvironment`. */ signature module MatchingWithEnvironmentInputSig { /** @@ -1297,6 +1644,15 @@ module Make1 Input1> { bindingset[apos] bindingset[dpos] predicate accessDeclarationPositionMatch(AccessPosition apos, DeclarationPosition dpos); + + /** + * Gets the variance relation of an inferred access type to its declared type. + * Arguments are covariant; contextual return types are contravariant. + */ + bindingset[apos] + default MatchingRelation getAccessTypeRelation(AccessPosition apos) { + exists(apos) and result.isCovariant() + } } /** @@ -1422,6 +1778,8 @@ module Make1 Input1> { bindingset[target] abstract Type getConstraintTypeAt(Declaration target, TypePath path); + MatchingRelation getRelation() { result.isCovariant() } + bindingset[a, e] abstract Type getInferredType(Access a, AccessEnvironment e, TypePath path); @@ -1525,6 +1883,10 @@ module Make1 Input1> { RelevantConstraint() { this = MkRelevantConstraint(target, pos) } + Declaration getTarget() { result = target } + + ConstraintPosition getPosition() { result = pos } + pragma[nomagic] predicate isRelevantFor(Access a, ConstraintPosition pos_, AccessEnvironment e) { pos.relevantFor(a, e, target) and @@ -1610,6 +1972,114 @@ module Make1 Input1> { SatisfiesConstraintWithTypeMatching; + private newtype TRecursiveAccess = + MkRecursiveAccess( + Access a, AccessEnvironment e, AccessPosition apos, Declaration target, + DeclarationPosition dpos + ) { + target = a.getTarget(e) and + accessDeclarationPositionMatch(apos, dpos) and + exists(target.getDeclaredType(dpos, TypePath::nil())) + } + + private class RecursiveAccess extends MkRecursiveAccess { + Access a; + AccessEnvironment e; + AccessPosition apos; + Declaration target; + DeclarationPosition dpos; + + RecursiveAccess() { this = MkRecursiveAccess(a, e, apos, target, dpos) } + + Access getAccess() { result = a } + + AccessEnvironment getEnvironment() { result = e } + + AccessPosition getAccessPosition() { result = apos } + + Declaration getTarget() { result = target } + + DeclarationPosition getDeclarationPosition() { result = dpos } + + Type getTypeAt(TypePath path) { result = a.getInferredType(e, apos, path) } + + string toString() { result = a.toString() + ", " + apos.toString() } + + Location getLocation() { result = a.getLocation() } + } + + private newtype TRecursiveConstraint = + MkRecursiveConstraint(Declaration target, DeclarationPosition dpos) { + exists(target.getDeclaredType(dpos, TypePath::nil())) + } + + private class RecursiveConstraint extends MkRecursiveConstraint { + Declaration target; + DeclarationPosition dpos; + + RecursiveConstraint() { this = MkRecursiveConstraint(target, dpos) } + + Declaration getTarget() { result = target } + + DeclarationPosition getDeclarationPosition() { result = dpos } + + Type getTypeAt(TypePath path) { result = target.getDeclaredType(dpos, path) } + + string toString() { result = target.toString() + ", " + dpos.toString() } + + Location getLocation() { result = target.getLocation() } + } + + private module VarianceInput implements + VarianceMatchingInputSig + { + predicate relevantConstraint(RecursiveAccess term, RecursiveConstraint constraint) { + varianceEnabled() and + term.getTarget() = constraint.getTarget() and + term.getDeclarationPosition() = constraint.getDeclarationPosition() + } + + MatchingRelation getRelation(RecursiveAccess term, RecursiveConstraint constraint) { + relevantConstraint(term, constraint) and + result = getAccessTypeRelation(term.getAccessPosition()) + } + + Type getTypeArgument( + RecursiveAccess term, RecursiveConstraint constraint, TypeParameter tp, TypePath path + ) { + typeMatch(term.getAccess(), term.getEnvironment(), constraint.getTarget(), path, result, + tp) + } + } + + private module RecursiveMatching = + VarianceMatching; + + pragma[nomagic] + predicate typeBound( + Access a, AccessEnvironment e, Declaration target, TypeParameter tp, + MatchingRelation relation, TypePath path, Type t + ) { + hasNotTypeArgument(a, target, tp) and + exists(AccessPosition apos, DeclarationPosition dpos | + accessDeclarationPositionMatch(apos, dpos) and + RecursiveMatching::typeBound(MkRecursiveAccess(a, e, apos, target, dpos), + MkRecursiveConstraint(target, dpos), tp, relation, path, t) + ) + } + + pragma[nomagic] + Type contextualType(Access a, AccessEnvironment e, AccessPosition apos, TypePath path) { + exists(Declaration target, DeclarationPosition dpos, TypePath suffix | + target = a.getTarget(e) and + accessDeclarationPositionMatch(apos, dpos) and + result = + RecursiveMatching::contextualType(MkRecursiveAccess(a, e, apos, target, dpos), + MkRecursiveConstraint(target, dpos), suffix) and + path = suffix + ) + } + /** * Holds if the (transitive) base type `t` at `path` of `a` in environment `e` * for some argument or type argument position matches the type parameter @@ -1728,6 +2198,24 @@ module Make1 Input1> { or // We can infer the type of `tp` via the type hierarchy or a type constraint ConstraintMatching::baseTypeMatch(a, e, target, path, t, tp) + or + varianceEnabled() and typeMatchBound(a, e, target, tp, _, path, t) + } + + /** + * Holds if `t` at `path` is a possible directional bound on `tp`. + * Covariance denotes a lower bound, contravariance an upper bound, and + * invariance equality. + * Like `typeMatch`, this preserves possible alternatives rather than + * selecting a least upper bound or rejecting inconsistent combinations. + */ + predicate typeMatchBound( + Access a, AccessEnvironment e, Declaration target, TypeParameter tp, + MatchingRelation relation, TypePath path, Type t + ) { + explicitTypeMatch(a, e, target, path, t, tp) and relation.isInvariant() + or + ConstraintMatching::typeBound(a, e, target, tp, relation, path, t) } /** @@ -1770,6 +2258,8 @@ module Make1 Input1> { */ pragma[nomagic] Type inferAccessType(Access a, AccessEnvironment e, AccessPosition apos, TypePath path) { + varianceEnabled() and result = ConstraintMatching::contextualType(a, e, apos, path) + or exists(DeclarationPosition dpos | accessDeclarationPositionMatch(apos, dpos) | // A suffix of `path` leads to a type parameter in the target exists(Declaration target, TypePath prefix, TypeParameter tp, TypePath suffix | @@ -1992,6 +2482,12 @@ module Make1 Input1> { bindingset[apos] bindingset[dpos] predicate accessDeclarationPositionMatch(AccessPosition apos, DeclarationPosition dpos); + + /** Gets the relation of an inferred access type to its declared type. */ + bindingset[apos] + default MatchingRelation getAccessTypeRelation(AccessPosition apos) { + exists(apos) and result.isCovariant() + } } /** @@ -2007,6 +2503,8 @@ module Make1 Input1> { predicate getATypeParameterConstraint = Input::getATypeParameterConstraint/2; + predicate getAccessTypeRelation = Input::getAccessTypeRelation/1; + class AccessEnvironment = Unit; final private class AccessFinal = Input::Access; @@ -3091,6 +3589,11 @@ module Make1 Input1> { class AccessPosition = DeclarationPosition; + bindingset[apos] + MatchingRelation getAccessTypeRelation(AccessPosition apos) { + if apos = getReturnPosition() then result.isContravariant() else result.isCovariant() + } + bindingset[apos] bindingset[dpos] predicate accessDeclarationPositionMatch(AccessPosition apos, DeclarationPosition dpos) { @@ -3155,8 +3658,12 @@ module Make1 Input1> { pragma[nomagic] private Type getInferredReturnType(AccessPosition apos, TypePath path) { - result = inferInvocationTypeContextual(this, path) and - apos = getReturnPosition() + apos = getReturnPosition() and + ( + result = inferInvocationTypeContextual(this, path) + or + varianceEnabled() and result = ContextualTyping::inferTypeForMatching(this, path) + ) } bindingset[e] @@ -3326,6 +3833,17 @@ module Make1 Input1> { ) } + /** + * Gets an expected type tree before filtering paths against the inferred + * constructor. Matching must first project through the hierarchy: an + * expected `Base` and an inferred `Derived` use different paths. + */ + pragma[nomagic] + Type inferTypeForMatching(AstNode n, TypePath path) { + hasUnknownType(n) and + result = inferTypeContextualCand0(n, path) + } + pragma[nomagic] private Type inferTypeContextualCand1(AstNode n, TypePath prefix, TypePath path) { result = inferTypeContextualCand0(n, path) and diff --git a/unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll b/unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll index bcfa0f38c1bf..6ed1c23c688f 100644 --- a/unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll +++ b/unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll @@ -19,6 +19,7 @@ private import codeql.util.Unit private import codeql.typeinference.internal.TypeInference +private import codeql.typeinference.internal.TypeInference as TypeInferenceInternal private import codeql.unified.internal.ParameterEx private import codeql.unified.internal.ExprPositions private import codeql.unified.internal.NameBinding @@ -33,6 +34,10 @@ private import TypeInferencePlugin as Plugin class Type = T::Type; +class Variance = TypeInferenceInternal::Variance; + +class MatchingRelation = TypeInferenceInternal::MatchingRelation; + private module Input1 implements InputSig1 { private import Type as T @@ -44,6 +49,10 @@ private module Input1 implements InputSig1 { class TypeAbstraction = TA::TypeAbstraction; + Variance getTypeParameterVariance(TypeParameter tp) { + result = any(Plugin::TypeInferencePlugin pl).getTypeParameterVariance(tp) + } + int getTypeParameterId(TypeParameter tp) { CachedStage::ref() and tp = diff --git a/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePlugin.qll b/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePlugin.qll index 097b2edfb6b2..458b96b0744c 100644 --- a/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePlugin.qll +++ b/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePlugin.qll @@ -28,6 +28,9 @@ class TypeInferencePlugin extends Unit { /** Gets the type parameter representing the element type of an array. */ abstract TypeParameter getArrayElementTypeParameter(); + /** Gets a non-invariant variance of a type parameter; absence means invariance. */ + Variance getTypeParameterVariance(TypeParameter tp) { none() } + /** * Gets the type of the given function expression. * @@ -36,6 +39,9 @@ class TypeInferencePlugin extends Unit { bindingset[fe] abstract Type getFunctionExprType(FunctionExpr fe); + /** Gets an intermediate constructor in the type tree of a function signature. */ + Type getFunctionExprIntermediateType(FunctionExpr fe, TypePath path) { none() } + /** * Gets the type path for the `i`th parameter of the given function type * when the function type has the given arity. @@ -128,6 +134,10 @@ TypePath getFunctionExprReturnTypePath(Type t) { result = any(TypeInferencePlugin pl).getFunctionExprReturnTypePath(t) } +Type getFunctionExprIntermediateType(FunctionExpr fe, TypePath path) { + result = any(TypeInferencePlugin pl).getFunctionExprIntermediateType(fe, path) +} + class TupleType extends Type { int arity; diff --git a/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePluginSwift.qll b/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePluginSwift.qll index e5358a049808..8915cafbfb31 100644 --- a/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePluginSwift.qll +++ b/unified/ql/lib/codeql/unified/internal/typeinference/TypeInferencePluginSwift.qll @@ -97,6 +97,23 @@ TypeParameter getTupleTypeParameter(int arity, int i) { private predicate inferTypeAlias = inferType/2; private class SwiftTypeInferencePlugin extends Plugin::TypeInferencePlugin { + override Variance getTypeParameterVariance(TypeParameter tp) { + tp = getFunctionArgsTypeParameter() and result.isContravariant() + or + ( + tp = getFunctionReturnTypeParameter() + or + tp instanceof ParentTypeParameterType + or + tp = any(TupleType t).getATypeParameter() + or + tp = any(ArrayType t).getATypeParameter() + or + tp = any(OptionalType t).getATypeParameter() + ) and + result.isCovariant() + } + override Type getBoolType() { result instanceof BoolType } override Type getIntType() { result instanceof IntType } @@ -115,6 +132,11 @@ private class SwiftTypeInferencePlugin extends Plugin::TypeInferencePlugin { exists(fe) } + override Type getFunctionExprIntermediateType(FunctionExpr fe, TypePath path) { + result = this.getTupleType(fe.getNumberOfParameters()) and + path = TypePath::singleton(getFunctionArgsTypeParameter()) + } + bindingset[t] override TypePath getFunctionExprParameterTypePath(Type t, int arity, int i) { result = functionParameterPath(arity, i) and exists(t) diff --git a/unified/ql/lib/codeql/unified/internal/typeinference/TypeMention.qll b/unified/ql/lib/codeql/unified/internal/typeinference/TypeMention.qll index 702a7351f276..034802da26fe 100644 --- a/unified/ql/lib/codeql/unified/internal/typeinference/TypeMention.qll +++ b/unified/ql/lib/codeql/unified/internal/typeinference/TypeMention.qll @@ -164,6 +164,8 @@ class ExprTypeMention extends TypeMentionImpl, Expr { result = this.getUnexpandedType() and path.isEmpty() or + result = Plugin::getFunctionExprIntermediateType(this.(FunctionExpr), path) + or exists( ClassLikeDeclaration c, AssociatedTypeDeclaration a, ClassLikeDeclaration base, AssociatedTypeParameterType baseTp, string name diff --git a/unified/ql/test/library-tests/type-inference/nested_types.swift b/unified/ql/test/library-tests/type-inference/nested_types.swift index c5a9e7406ad6..1fde7b9789ff 100644 --- a/unified/ql/test/library-tests/type-inference/nested_types.swift +++ b/unified/ql/test/library-tests/type-inference/nested_types.swift @@ -214,7 +214,7 @@ var y7 = innerMost.getOuter() // $ target=Outer.Inner.InnerMost.getOuter $ MISS class SubOuter: Outer<[TSubOuter]> { func f(_ x: Inner) -> [TSubOuter] { - let res = x.getOuter() // $ target=Outer.Inner.getOuter $ MISSING: type=res@Array:TSubOuter -- this is an instance of variance sub typing + let res = x.getOuter() // $ target=Outer.Inner.getOuter type=res@Array:TSubOuter return res } } @@ -321,10 +321,10 @@ class SubSub: Sub { x3: Element2, // $ type=x3@Base2.Nested<(parent:Nested)>:Sub x4: SubSub.Element2 // $ type=x4@Base2.Nested<(parent:Nested)>:Sub ) { - let a = x1.getX() // $ target=Base2.Nested.getX $ MISSING: type=a:String -- this is an instance of variance sub typing - let b = x2.getX() // $ target=Base2.Nested.getX $ MISSING: type=b:String -- this is an instance of variance sub typing - let c = x3.getX() // $ target=Base2.Nested.getX $ MISSING: type=c:String -- this is an instance of variance sub typing - let d = x4.getX() // $ target=Base2.Nested.getX $ MISSING: type=d:String -- this is an instance of variance sub typing + let a = x1.getX() // $ target=Base2.Nested.getX type=a:String + let b = x2.getX() // $ target=Base2.Nested.getX type=b:String + let c = x3.getX() // $ target=Base2.Nested.getX type=c:String + let d = x4.getX() // $ target=Base2.Nested.getX type=d:String } } diff --git a/unified/ql/test/library-tests/type-inference/type-inference.expected b/unified/ql/test/library-tests/type-inference/type-inference.expected index f7d83c6df419..14f233f3d1a5 100644 --- a/unified/ql/test/library-tests/type-inference/type-inference.expected +++ b/unified/ql/test/library-tests/type-inference/type-inference.expected @@ -1268,6 +1268,198 @@ inferCertainType | variance.swift:13:16:13:18 | lam | Return.Tb | {EXTERNAL LOCATION} | String | | variance.swift:18:7:18:7 | x | | variance.swift:3:1:3:14 | A | | variance.swift:18:7:18:7 | x | Ta | {EXTERNAL LOCATION} | Int | +| variance.swift:21:22:21:26 | value | | {EXTERNAL LOCATION} | Array | +| variance.swift:21:22:21:26 | value | Element | variance.swift:21:17:21:17 | T | +| variance.swift:22:5:22:20 | boundLowerActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:22:24:22:26 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:23:24:23:39 | boundLowerActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:25:22:25:29 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:25:22:25:29 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:25:22:25:29 | callback | Args.T0 | variance.swift:25:17:25:17 | T | +| variance.swift:25:22:25:29 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:26:5:26:20 | boundUpperActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:26:5:26:20 | boundUpperActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:26:5:26:20 | boundUpperActual | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:26:5:26:20 | boundUpperActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:26:24:26:55 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| variance.swift:26:24:26:55 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:26:24:26:55 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:26:24:26:55 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:26:27:26:31 | value | | {EXTERNAL LOCATION} | Int | +| variance.swift:26:49:26:53 | Block | | {EXTERNAL LOCATION} | Int | +| variance.swift:26:49:26:53 | value | | {EXTERNAL LOCATION} | Int | +| variance.swift:27:24:27:39 | boundUpperActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:27:24:27:39 | boundUpperActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:27:24:27:39 | boundUpperActual | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:27:24:27:39 | boundUpperActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:29:23:29:30 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:29:23:29:30 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:29:23:29:30 | callback | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:29:23:29:30 | callback | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:29:23:29:30 | callback | Args.T0.Args.T0 | variance.swift:29:18:29:18 | T | +| variance.swift:29:23:29:30 | callback | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:29:23:29:30 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:5:30:21 | boundDoubleActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:30:5:30:21 | boundDoubleActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:5:30:21 | boundDoubleActual | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:30:5:30:21 | boundDoubleActual | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:5:30:21 | boundDoubleActual | Args.T0.Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:30:5:30:21 | boundDoubleActual | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:5:30:21 | boundDoubleActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:25:30:74 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| variance.swift:30:25:30:74 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:25:30:74 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:30:25:30:74 | FunctionExpr | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:25:30:74 | FunctionExpr | Args.T0.Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:30:25:30:74 | FunctionExpr | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:25:30:74 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:28:30:35 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:30:28:30:35 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:28:30:35 | callback | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:30:28:30:35 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:62:30:69 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:30:62:30:69 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:62:30:69 | callback | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:30:62:30:69 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:31:26:31:42 | boundDoubleActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:31:26:31:42 | boundDoubleActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:31:26:31:42 | boundDoubleActual | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:31:26:31:42 | boundDoubleActual | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:31:26:31:42 | boundDoubleActual | Args.T0.Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:31:26:31:42 | boundDoubleActual | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:31:26:31:42 | boundDoubleActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:33:26:33:30 | value | | variance.swift:3:1:3:14 | A | +| variance.swift:33:26:33:30 | value | Ta | variance.swift:33:21:33:21 | T | +| variance.swift:37:23:37:27 | value | | {EXTERNAL LOCATION} | Array | +| variance.swift:37:23:37:27 | value | Element | variance.swift:3:1:3:14 | A | +| variance.swift:37:23:37:27 | value | Element.Ta | variance.swift:37:18:37:18 | T | +| variance.swift:38:5:38:21 | boundNestedActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:38:25:38:34 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:39:26:39:42 | boundNestedActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:43:31:43:35 | value | | {EXTERNAL LOCATION} | Array | +| variance.swift:43:31:43:35 | value | Element | variance.swift:5:1:5:21 | B | +| variance.swift:43:31:43:35 | value | Element.Tb | variance.swift:43:26:43:26 | T | +| variance.swift:44:5:44:29 | boundWrongDirectionActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:44:33:44:42 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:45:42:45:66 | boundWrongDirectionActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:47:36:47:40 | value | | variance.swift:3:1:3:14 | A | +| variance.swift:47:36:47:40 | value | Ta | variance.swift:3:1:3:14 | A | +| variance.swift:47:36:47:40 | value | Ta.Ta | variance.swift:47:31:47:31 | T | +| variance.swift:51:24:51:28 | first | | variance.swift:51:19:51:19 | T | +| variance.swift:51:36:51:41 | values | | {EXTERNAL LOCATION} | Array | +| variance.swift:51:36:51:41 | values | Element | variance.swift:3:1:3:14 | A | +| variance.swift:51:36:51:41 | values | Element.Ta | variance.swift:51:19:51:19 | T | +| variance.swift:52:17:52:21 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:54:29:54:33 | first | | {EXTERNAL LOCATION} | Array | +| variance.swift:54:29:54:33 | first | Element | variance.swift:54:24:54:24 | T | +| variance.swift:54:43:54:48 | second | | {EXTERNAL LOCATION} | Array | +| variance.swift:54:43:54:48 | second | Element | variance.swift:54:24:54:24 | T | +| variance.swift:55:38:55:40 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:55:43:55:47 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:58:22:58:29 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:58:22:58:29 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:58:22:58:29 | callback | Args.T0 | variance.swift:58:17:58:17 | T | +| variance.swift:58:22:58:29 | callback | Return | variance.swift:58:17:58:17 | T | +| variance.swift:59:5:59:20 | boundMixedActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:59:5:59:20 | boundMixedActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:59:5:59:20 | boundMixedActual | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:59:5:59:20 | boundMixedActual | Return | {EXTERNAL LOCATION} | String | +| variance.swift:59:24:59:56 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| variance.swift:59:24:59:56 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:59:24:59:56 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:59:24:59:56 | FunctionExpr | Return | {EXTERNAL LOCATION} | String | +| variance.swift:59:27:59:31 | value | | {EXTERNAL LOCATION} | Int | +| variance.swift:60:24:60:39 | boundMixedActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:60:24:60:39 | boundMixedActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:60:24:60:39 | boundMixedActual | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:60:24:60:39 | boundMixedActual | Return | {EXTERNAL LOCATION} | String | +| variance.swift:65:22:65:26 | value | | {EXTERNAL LOCATION} | Array | +| variance.swift:65:22:65:26 | value | Element | variance.swift:3:1:3:14 | A | +| variance.swift:65:22:65:26 | value | Element.Ta | {EXTERNAL LOCATION} | Array | +| variance.swift:65:22:65:26 | value | Element.Ta.Element | variance.swift:65:17:65:17 | T | +| variance.swift:66:5:66:20 | boundShiftActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:66:24:66:37 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:67:26:67:41 | boundShiftActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:69:26:69:30 | first | | variance.swift:69:21:69:21 | T | +| variance.swift:69:38:69:43 | values | | {EXTERNAL LOCATION} | Array | +| variance.swift:69:38:69:43 | values | Element | variance.swift:3:1:3:14 | A | +| variance.swift:69:38:69:43 | values | Element.Ta | {EXTERNAL LOCATION} | Array | +| variance.swift:69:38:69:43 | values | Element.Ta.Element | variance.swift:69:21:69:21 | T | +| variance.swift:70:19:70:27 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:72:30:72:37 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:72:30:72:37 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:72:30:72:37 | callback | Args.T0 | variance.swift:3:1:3:14 | A | +| variance.swift:72:30:72:37 | callback | Args.T0.Ta | variance.swift:72:25:72:25 | T | +| variance.swift:72:30:72:37 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:73:5:73:28 | boundContraReverseActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:73:5:73:28 | boundContraReverseActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:73:5:73:28 | boundContraReverseActual | Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:73:5:73:28 | boundContraReverseActual | Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:73:5:73:28 | boundContraReverseActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:73:32:73:62 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| variance.swift:73:32:73:62 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:73:32:73:62 | FunctionExpr | Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:73:32:73:62 | FunctionExpr | Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:73:32:73:62 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:73:35:73:39 | value | | variance.swift:5:1:5:21 | B | +| variance.swift:73:35:73:39 | value | Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:74:40:74:63 | boundContraReverseActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:74:40:74:63 | boundContraReverseActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:74:40:74:63 | boundContraReverseActual | Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:74:40:74:63 | boundContraReverseActual | Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:74:40:74:63 | boundContraReverseActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:76:29:76:36 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:76:29:76:36 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:76:29:76:36 | callback | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:76:29:76:36 | callback | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:76:29:76:36 | callback | Args.T0.Args.T0 | variance.swift:3:1:3:14 | A | +| variance.swift:76:29:76:36 | callback | Args.T0.Args.T0.Ta | variance.swift:76:24:76:24 | T | +| variance.swift:76:29:76:36 | callback | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:76:29:76:36 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args.T0.Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args.T0.Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:31:77:73 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| variance.swift:77:31:77:73 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:77:31:77:73 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:77:31:77:73 | FunctionExpr | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:77:31:77:73 | FunctionExpr | Args.T0.Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:77:31:77:73 | FunctionExpr | Args.T0.Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:77:31:77:73 | FunctionExpr | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:31:77:73 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:34:77:41 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:77:34:77:41 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:77:34:77:41 | callback | Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:77:34:77:41 | callback | Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:77:34:77:41 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args.T0.Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args.T0.Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:80:34:80:38 | value | | variance.swift:3:1:3:14 | A | +| variance.swift:80:34:80:38 | value | Ta | {EXTERNAL LOCATION} | Function | +| variance.swift:80:34:80:38 | value | Ta.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:80:34:80:38 | value | Ta.Args.T0 | variance.swift:3:1:3:14 | A | +| variance.swift:80:34:80:38 | value | Ta.Args.T0.Ta | variance.swift:80:29:80:29 | T | +| variance.swift:80:34:80:38 | value | Ta.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:84:25:84:29 | value | | {EXTERNAL LOCATION} | Optional | +| variance.swift:84:25:84:29 | value | Wrapped | variance.swift:3:1:3:14 | A | +| variance.swift:84:25:84:29 | value | Wrapped.Ta | variance.swift:84:20:84:20 | T | +| variance.swift:85:5:85:23 | boundOptionalActual | | {EXTERNAL LOCATION} | Optional | +| variance.swift:85:5:85:23 | boundOptionalActual | Wrapped | variance.swift:5:1:5:21 | B | +| variance.swift:85:5:85:23 | boundOptionalActual | Wrapped.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:86:30:86:48 | boundOptionalActual | | {EXTERNAL LOCATION} | Optional | +| variance.swift:86:30:86:48 | boundOptionalActual | Wrapped | variance.swift:5:1:5:21 | B | +| variance.swift:86:30:86:48 | boundOptionalActual | Wrapped.Tb | {EXTERNAL LOCATION} | Int | inferType | accessors.swift:4:7:4:12 | stored | | {EXTERNAL LOCATION} | Int | | accessors.swift:4:21:4:21 | 0 | | {EXTERNAL LOCATION} | Int | @@ -1422,11 +1614,13 @@ inferType | accessors.swift:143:34:143:36 | Block | | {EXTERNAL LOCATION} | String | | accessors.swift:146:9:146:14 | result | | {EXTERNAL LOCATION} | String | | accessors.swift:146:18:146:25 | callback | | {EXTERNAL LOCATION} | Function | +| accessors.swift:146:18:146:25 | callback | Args | {EXTERNAL LOCATION} | Tuple0 | | accessors.swift:146:18:146:25 | callback | Return | {EXTERNAL LOCATION} | String | | accessors.swift:146:18:146:27 | callback(...) | | {EXTERNAL LOCATION} | String | | accessors.swift:147:9:147:15 | result2 | | {EXTERNAL LOCATION} | String | | accessors.swift:147:19:147:22 | self | | accessors.swift:142:1:149:1 | C | | accessors.swift:147:19:147:31 | ... .callback | | {EXTERNAL LOCATION} | Function | +| accessors.swift:147:19:147:31 | ... .callback | Args | {EXTERNAL LOCATION} | Tuple0 | | accessors.swift:147:19:147:31 | ... .callback | Return | {EXTERNAL LOCATION} | String | | accessors.swift:147:19:147:33 | ... .callback(...) | | {EXTERNAL LOCATION} | String | | accessors.swift:154:14:154:19 | stored | | {EXTERNAL LOCATION} | Int | @@ -3633,10 +3827,18 @@ inferType | nested_types.swift:216:14:216:14 | x | (parent:Inner) | nested_types.swift:215:1:220:1 | SubOuter | | nested_types.swift:216:14:216:14 | x | (parent:Inner).TSubOuter | nested_types.swift:215:16:215:24 | TSubOuter | | nested_types.swift:216:14:216:14 | x | TInner | {EXTERNAL LOCATION} | String | +| nested_types.swift:216:47:219:5 | Block | | {EXTERNAL LOCATION} | Array | +| nested_types.swift:216:47:219:5 | Block | Element | nested_types.swift:215:16:215:24 | TSubOuter | +| nested_types.swift:217:13:217:15 | res | | {EXTERNAL LOCATION} | Array | +| nested_types.swift:217:13:217:15 | res | Element | nested_types.swift:215:16:215:24 | TSubOuter | | nested_types.swift:217:19:217:19 | x | | nested_types.swift:14:5:47:5 | Outer.Inner | | nested_types.swift:217:19:217:19 | x | (parent:Inner) | nested_types.swift:215:1:220:1 | SubOuter | | nested_types.swift:217:19:217:19 | x | (parent:Inner).TSubOuter | nested_types.swift:215:16:215:24 | TSubOuter | | nested_types.swift:217:19:217:19 | x | TInner | {EXTERNAL LOCATION} | String | +| nested_types.swift:217:19:217:30 | ... .getOuter(...) | | {EXTERNAL LOCATION} | Array | +| nested_types.swift:217:19:217:30 | ... .getOuter(...) | Element | nested_types.swift:215:16:215:24 | TSubOuter | +| nested_types.swift:218:16:218:18 | res | | {EXTERNAL LOCATION} | Array | +| nested_types.swift:218:16:218:18 | res | Element | nested_types.swift:215:16:215:24 | TSubOuter | | nested_types.swift:222:5:222:12 | subOuter | | nested_types.swift:14:5:47:5 | Outer.Inner | | nested_types.swift:222:5:222:12 | subOuter | (parent:Inner) | nested_types.swift:13:1:130:1 | Outer | | nested_types.swift:222:5:222:12 | subOuter | (parent:Inner).TOuter | {EXTERNAL LOCATION} | Array | @@ -3847,14 +4049,22 @@ inferType | nested_types.swift:321:9:321:10 | x3 | (parent:Nested) | nested_types.swift:312:1:316:1 | Sub | | nested_types.swift:322:9:322:10 | x4 | | nested_types.swift:304:5:310:5 | Base2.Nested | | nested_types.swift:322:9:322:10 | x4 | (parent:Nested) | nested_types.swift:312:1:316:1 | Sub | +| nested_types.swift:324:13:324:13 | a | | {EXTERNAL LOCATION} | String | | nested_types.swift:324:17:324:18 | x1 | | nested_types.swift:304:5:310:5 | Base2.Nested | | nested_types.swift:324:17:324:18 | x1 | (parent:Nested) | nested_types.swift:312:1:316:1 | Sub | +| nested_types.swift:324:17:324:25 | ... .getX(...) | | {EXTERNAL LOCATION} | String | +| nested_types.swift:325:13:325:13 | b | | {EXTERNAL LOCATION} | String | | nested_types.swift:325:17:325:18 | x2 | | nested_types.swift:304:5:310:5 | Base2.Nested | | nested_types.swift:325:17:325:18 | x2 | (parent:Nested) | nested_types.swift:312:1:316:1 | Sub | +| nested_types.swift:325:17:325:25 | ... .getX(...) | | {EXTERNAL LOCATION} | String | +| nested_types.swift:326:13:326:13 | c | | {EXTERNAL LOCATION} | String | | nested_types.swift:326:17:326:18 | x3 | | nested_types.swift:304:5:310:5 | Base2.Nested | | nested_types.swift:326:17:326:18 | x3 | (parent:Nested) | nested_types.swift:312:1:316:1 | Sub | +| nested_types.swift:326:17:326:25 | ... .getX(...) | | {EXTERNAL LOCATION} | String | +| nested_types.swift:327:13:327:13 | d | | {EXTERNAL LOCATION} | String | | nested_types.swift:327:17:327:18 | x4 | | nested_types.swift:304:5:310:5 | Base2.Nested | | nested_types.swift:327:17:327:18 | x4 | (parent:Nested) | nested_types.swift:312:1:316:1 | Sub | +| nested_types.swift:327:17:327:25 | ... .getX(...) | | {EXTERNAL LOCATION} | String | | nested_types.swift:335:17:335:17 | a | | nested_types.swift:331:9:331:10 | Ta | | nested_types.swift:336:17:336:17 | b | | nested_types.swift:333:13:333:14 | Tb | | nested_types.swift:337:17:337:17 | c | | nested_types.swift:334:17:334:18 | Tc | @@ -5079,7 +5289,11 @@ inferType | variance.swift:11:41:11:51 | Block | | variance.swift:5:1:5:21 | B | | variance.swift:11:41:11:51 | Block | Tb | {EXTERNAL LOCATION} | String | | variance.swift:13:5:13:5 | x | | {EXTERNAL LOCATION} | Tuple2 | +| variance.swift:13:5:13:5 | x | T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:13:5:13:5 | x | T1 | {EXTERNAL LOCATION} | String | | variance.swift:13:9:13:19 | foo(...) | | {EXTERNAL LOCATION} | Tuple2 | +| variance.swift:13:9:13:19 | foo(...) | T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:13:9:13:19 | foo(...) | T1 | {EXTERNAL LOCATION} | String | | variance.swift:13:16:13:18 | lam | | {EXTERNAL LOCATION} | Function | | variance.swift:13:16:13:18 | lam | Args | {EXTERNAL LOCATION} | Tuple1 | | variance.swift:13:16:13:18 | lam | Args.T0 | variance.swift:3:1:3:14 | A | @@ -5095,4 +5309,339 @@ inferType | variance.swift:18:7:18:7 | x | | variance.swift:3:1:3:14 | A | | variance.swift:18:7:18:7 | x | Ta | {EXTERNAL LOCATION} | Int | | variance.swift:18:19:18:23 | bar(...) | | variance.swift:5:1:5:21 | B | +| variance.swift:18:19:18:23 | bar(...) | Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:21:22:21:26 | value | | {EXTERNAL LOCATION} | Array | +| variance.swift:21:22:21:26 | value | Element | variance.swift:21:17:21:17 | T | +| variance.swift:22:5:22:20 | boundLowerActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:22:5:22:20 | boundLowerActual | Element | {EXTERNAL LOCATION} | Int | +| variance.swift:22:24:22:26 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:22:24:22:26 | ArrayLiteral | Element | {EXTERNAL LOCATION} | Int | +| variance.swift:22:25:22:25 | 1 | | {EXTERNAL LOCATION} | Int | +| variance.swift:23:5:23:9 | lower | | {EXTERNAL LOCATION} | Int | +| variance.swift:23:13:23:40 | boundLower(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:23:24:23:39 | boundLowerActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:23:24:23:39 | boundLowerActual | Element | {EXTERNAL LOCATION} | Int | +| variance.swift:25:22:25:29 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:25:22:25:29 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:25:22:25:29 | callback | Args.T0 | variance.swift:25:17:25:17 | T | +| variance.swift:25:22:25:29 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:26:5:26:20 | boundUpperActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:26:5:26:20 | boundUpperActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:26:5:26:20 | boundUpperActual | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:26:5:26:20 | boundUpperActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:26:24:26:55 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| variance.swift:26:24:26:55 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:26:24:26:55 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:26:24:26:55 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:26:27:26:31 | value | | {EXTERNAL LOCATION} | Int | +| variance.swift:26:49:26:53 | Block | | {EXTERNAL LOCATION} | Int | +| variance.swift:26:49:26:53 | value | | {EXTERNAL LOCATION} | Int | +| variance.swift:27:5:27:9 | upper | | {EXTERNAL LOCATION} | Int | +| variance.swift:27:13:27:40 | boundUpper(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:27:24:27:39 | boundUpperActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:27:24:27:39 | boundUpperActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:27:24:27:39 | boundUpperActual | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:27:24:27:39 | boundUpperActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:29:23:29:30 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:29:23:29:30 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:29:23:29:30 | callback | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:29:23:29:30 | callback | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:29:23:29:30 | callback | Args.T0.Args.T0 | variance.swift:29:18:29:18 | T | +| variance.swift:29:23:29:30 | callback | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:29:23:29:30 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:5:30:21 | boundDoubleActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:30:5:30:21 | boundDoubleActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:5:30:21 | boundDoubleActual | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:30:5:30:21 | boundDoubleActual | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:5:30:21 | boundDoubleActual | Args.T0.Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:30:5:30:21 | boundDoubleActual | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:5:30:21 | boundDoubleActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:25:30:74 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| variance.swift:30:25:30:74 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:25:30:74 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:30:25:30:74 | FunctionExpr | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:25:30:74 | FunctionExpr | Args.T0.Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:30:25:30:74 | FunctionExpr | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:25:30:74 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:28:30:35 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:30:28:30:35 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:28:30:35 | callback | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:30:28:30:35 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:62:30:69 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:30:62:30:69 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:30:62:30:69 | callback | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:30:62:30:69 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:30:62:30:72 | Block | | {EXTERNAL LOCATION} | Int | +| variance.swift:30:62:30:72 | callback(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:30:71:30:71 | 1 | | {EXTERNAL LOCATION} | Int | +| variance.swift:31:5:31:10 | double | | {EXTERNAL LOCATION} | Int | +| variance.swift:31:14:31:43 | boundDouble(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:31:26:31:42 | boundDoubleActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:31:26:31:42 | boundDoubleActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:31:26:31:42 | boundDoubleActual | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:31:26:31:42 | boundDoubleActual | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:31:26:31:42 | boundDoubleActual | Args.T0.Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:31:26:31:42 | boundDoubleActual | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:31:26:31:42 | boundDoubleActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:33:26:33:30 | value | | variance.swift:3:1:3:14 | A | +| variance.swift:33:26:33:30 | value | Ta | variance.swift:33:21:33:21 | T | +| variance.swift:34:5:34:24 | boundInvariantActual | | variance.swift:3:1:3:14 | A | +| variance.swift:34:5:34:24 | boundInvariantActual | Ta | {EXTERNAL LOCATION} | Int | +| variance.swift:34:28:34:33 | GenericTypeExpr | | variance.swift:3:1:3:14 | A | +| variance.swift:34:28:34:33 | GenericTypeExpr | Ta | {EXTERNAL LOCATION} | Int | +| variance.swift:34:28:34:35 | ...(...) | | variance.swift:3:1:3:14 | A | +| variance.swift:34:28:34:35 | ...(...) | Ta | {EXTERNAL LOCATION} | Int | +| variance.swift:35:5:35:13 | invariant | | {EXTERNAL LOCATION} | Int | +| variance.swift:35:17:35:52 | boundInvariant(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:35:32:35:51 | boundInvariantActual | | variance.swift:3:1:3:14 | A | +| variance.swift:35:32:35:51 | boundInvariantActual | Ta | {EXTERNAL LOCATION} | Int | +| variance.swift:37:23:37:27 | value | | {EXTERNAL LOCATION} | Array | +| variance.swift:37:23:37:27 | value | Element | variance.swift:3:1:3:14 | A | +| variance.swift:37:23:37:27 | value | Element.Ta | variance.swift:37:18:37:18 | T | +| variance.swift:38:5:38:21 | boundNestedActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:38:5:38:21 | boundNestedActual | Element | variance.swift:5:1:5:21 | B | +| variance.swift:38:5:38:21 | boundNestedActual | Element.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:38:25:38:34 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:38:25:38:34 | ArrayLiteral | Element | variance.swift:5:1:5:21 | B | +| variance.swift:38:25:38:34 | ArrayLiteral | Element.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:38:26:38:31 | GenericTypeExpr | | variance.swift:5:1:5:21 | B | +| variance.swift:38:26:38:31 | GenericTypeExpr | Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:38:26:38:33 | ...(...) | | variance.swift:5:1:5:21 | B | +| variance.swift:38:26:38:33 | ...(...) | Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:39:5:39:10 | nested | | {EXTERNAL LOCATION} | Int | +| variance.swift:39:14:39:43 | boundNested(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:39:26:39:42 | boundNestedActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:39:26:39:42 | boundNestedActual | Element | variance.swift:5:1:5:21 | B | +| variance.swift:39:26:39:42 | boundNestedActual | Element.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:43:31:43:35 | value | | {EXTERNAL LOCATION} | Array | +| variance.swift:43:31:43:35 | value | Element | variance.swift:5:1:5:21 | B | +| variance.swift:43:31:43:35 | value | Element.Tb | variance.swift:43:26:43:26 | T | +| variance.swift:44:5:44:29 | boundWrongDirectionActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:44:5:44:29 | boundWrongDirectionActual | Element | variance.swift:3:1:3:14 | A | +| variance.swift:44:5:44:29 | boundWrongDirectionActual | Element.Ta | {EXTERNAL LOCATION} | Int | +| variance.swift:44:33:44:42 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:44:33:44:42 | ArrayLiteral | Element | variance.swift:3:1:3:14 | A | +| variance.swift:44:33:44:42 | ArrayLiteral | Element.Ta | {EXTERNAL LOCATION} | Int | +| variance.swift:44:34:44:39 | GenericTypeExpr | | variance.swift:3:1:3:14 | A | +| variance.swift:44:34:44:39 | GenericTypeExpr | Ta | {EXTERNAL LOCATION} | Int | +| variance.swift:44:34:44:41 | ...(...) | | variance.swift:3:1:3:14 | A | +| variance.swift:44:34:44:41 | ...(...) | Ta | {EXTERNAL LOCATION} | Int | +| variance.swift:45:42:45:66 | boundWrongDirectionActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:45:42:45:66 | boundWrongDirectionActual | Element | variance.swift:3:1:3:14 | A | +| variance.swift:45:42:45:66 | boundWrongDirectionActual | Element.Ta | {EXTERNAL LOCATION} | Int | +| variance.swift:47:36:47:40 | value | | variance.swift:3:1:3:14 | A | +| variance.swift:47:36:47:40 | value | Ta | variance.swift:3:1:3:14 | A | +| variance.swift:47:36:47:40 | value | Ta.Ta | variance.swift:47:31:47:31 | T | +| variance.swift:48:5:48:34 | boundInvariantConversionActual | | variance.swift:3:1:3:14 | A | +| variance.swift:48:5:48:34 | boundInvariantConversionActual | Ta | variance.swift:5:1:5:21 | B | +| variance.swift:48:5:48:34 | boundInvariantConversionActual | Ta.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:48:38:48:46 | GenericTypeExpr | | variance.swift:3:1:3:14 | A | +| variance.swift:48:38:48:46 | GenericTypeExpr | Ta | variance.swift:5:1:5:21 | B | +| variance.swift:48:38:48:46 | GenericTypeExpr | Ta.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:48:38:48:48 | ...(...) | | variance.swift:3:1:3:14 | A | +| variance.swift:48:38:48:48 | ...(...) | Ta | variance.swift:5:1:5:21 | B | +| variance.swift:48:38:48:48 | ...(...) | Ta.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:49:52:49:81 | boundInvariantConversionActual | | variance.swift:3:1:3:14 | A | +| variance.swift:49:52:49:81 | boundInvariantConversionActual | Ta | variance.swift:5:1:5:21 | B | +| variance.swift:49:52:49:81 | boundInvariantConversionActual | Ta.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:51:24:51:28 | first | | variance.swift:51:19:51:19 | T | +| variance.swift:51:36:51:41 | values | | {EXTERNAL LOCATION} | Array | +| variance.swift:51:36:51:41 | values | Element | variance.swift:3:1:3:14 | A | +| variance.swift:51:36:51:41 | values | Element.Ta | variance.swift:51:19:51:19 | T | +| variance.swift:52:14:52:14 | 1 | | {EXTERNAL LOCATION} | Int | +| variance.swift:52:17:52:21 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:52:17:52:21 | ArrayLiteral | Element | variance.swift:5:1:5:21 | B | +| variance.swift:52:17:52:21 | ArrayLiteral | Element.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:52:18:52:18 | B | | variance.swift:5:1:5:21 | B | +| variance.swift:52:18:52:18 | B | Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:52:18:52:20 | B(...) | | variance.swift:5:1:5:21 | B | +| variance.swift:52:18:52:20 | B(...) | Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:54:29:54:33 | first | | {EXTERNAL LOCATION} | Array | +| variance.swift:54:29:54:33 | first | Element | variance.swift:54:24:54:24 | T | +| variance.swift:54:43:54:48 | second | | {EXTERNAL LOCATION} | Array | +| variance.swift:54:43:54:48 | second | Element | variance.swift:54:24:54:24 | T | +| variance.swift:55:5:55:16 | alternatives | | {EXTERNAL LOCATION} | Int | +| variance.swift:55:5:55:16 | alternatives | | {EXTERNAL LOCATION} | String | +| variance.swift:55:20:55:48 | boundAlternatives(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:55:20:55:48 | boundAlternatives(...) | | {EXTERNAL LOCATION} | String | +| variance.swift:55:38:55:40 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:55:38:55:40 | ArrayLiteral | Element | {EXTERNAL LOCATION} | Int | +| variance.swift:55:39:55:39 | 1 | | {EXTERNAL LOCATION} | Int | +| variance.swift:55:43:55:47 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:55:43:55:47 | ArrayLiteral | Element | {EXTERNAL LOCATION} | String | +| variance.swift:55:44:55:46 | "x" | | {EXTERNAL LOCATION} | String | +| variance.swift:58:22:58:29 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:58:22:58:29 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:58:22:58:29 | callback | Args.T0 | variance.swift:58:17:58:17 | T | +| variance.swift:58:22:58:29 | callback | Return | variance.swift:58:17:58:17 | T | +| variance.swift:59:5:59:20 | boundMixedActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:59:5:59:20 | boundMixedActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:59:5:59:20 | boundMixedActual | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:59:5:59:20 | boundMixedActual | Return | {EXTERNAL LOCATION} | String | +| variance.swift:59:24:59:56 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| variance.swift:59:24:59:56 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:59:24:59:56 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:59:24:59:56 | FunctionExpr | Return | {EXTERNAL LOCATION} | String | +| variance.swift:59:27:59:31 | value | | {EXTERNAL LOCATION} | Int | +| variance.swift:59:52:59:54 | "x" | | {EXTERNAL LOCATION} | String | +| variance.swift:59:52:59:54 | Block | | {EXTERNAL LOCATION} | String | +| variance.swift:60:5:60:9 | mixed | | {EXTERNAL LOCATION} | Int | +| variance.swift:60:5:60:9 | mixed | | {EXTERNAL LOCATION} | String | +| variance.swift:60:13:60:40 | boundMixed(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:60:13:60:40 | boundMixed(...) | | {EXTERNAL LOCATION} | String | +| variance.swift:60:24:60:39 | boundMixedActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:60:24:60:39 | boundMixedActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:60:24:60:39 | boundMixedActual | Args.T0 | {EXTERNAL LOCATION} | Int | +| variance.swift:60:24:60:39 | boundMixedActual | Return | {EXTERNAL LOCATION} | String | +| variance.swift:63:19:63:34 | Block | | variance.swift:3:1:3:14 | A | +| variance.swift:63:19:63:34 | Block | Ta | {EXTERNAL LOCATION} | Array | +| variance.swift:63:19:63:34 | Block | Ta.Element | variance.swift:62:13:62:13 | C | +| variance.swift:63:21:63:25 | super | | variance.swift:3:1:3:14 | A | +| variance.swift:63:21:63:25 | super | Ta | {EXTERNAL LOCATION} | Array | +| variance.swift:63:21:63:25 | super | Ta.Element | variance.swift:62:13:62:13 | C | +| variance.swift:63:21:63:32 | ... .init(...) | | variance.swift:3:1:3:14 | A | +| variance.swift:63:21:63:32 | ... .init(...) | Ta | {EXTERNAL LOCATION} | Array | +| variance.swift:63:21:63:32 | ... .init(...) | Ta.Element | variance.swift:62:13:62:13 | C | +| variance.swift:65:22:65:26 | value | | {EXTERNAL LOCATION} | Array | +| variance.swift:65:22:65:26 | value | Element | variance.swift:3:1:3:14 | A | +| variance.swift:65:22:65:26 | value | Element.Ta | {EXTERNAL LOCATION} | Array | +| variance.swift:65:22:65:26 | value | Element.Ta.Element | variance.swift:65:17:65:17 | T | +| variance.swift:66:5:66:20 | boundShiftActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:66:5:66:20 | boundShiftActual | Element | variance.swift:62:1:64:1 | Shift | +| variance.swift:66:5:66:20 | boundShiftActual | Element.C | {EXTERNAL LOCATION} | Int | +| variance.swift:66:24:66:37 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:66:24:66:37 | ArrayLiteral | Element | variance.swift:62:1:64:1 | Shift | +| variance.swift:66:24:66:37 | ArrayLiteral | Element.C | {EXTERNAL LOCATION} | Int | +| variance.swift:66:25:66:34 | GenericTypeExpr | | variance.swift:62:1:64:1 | Shift | +| variance.swift:66:25:66:34 | GenericTypeExpr | C | {EXTERNAL LOCATION} | Int | +| variance.swift:66:25:66:36 | ...(...) | | variance.swift:62:1:64:1 | Shift | +| variance.swift:66:25:66:36 | ...(...) | C | {EXTERNAL LOCATION} | Int | +| variance.swift:67:5:67:11 | shifted | | {EXTERNAL LOCATION} | Int | +| variance.swift:67:15:67:42 | boundShift(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:67:26:67:41 | boundShiftActual | | {EXTERNAL LOCATION} | Array | +| variance.swift:67:26:67:41 | boundShiftActual | Element | variance.swift:62:1:64:1 | Shift | +| variance.swift:67:26:67:41 | boundShiftActual | Element.C | {EXTERNAL LOCATION} | Int | +| variance.swift:69:26:69:30 | first | | variance.swift:69:21:69:21 | T | +| variance.swift:69:38:69:43 | values | | {EXTERNAL LOCATION} | Array | +| variance.swift:69:38:69:43 | values | Element | variance.swift:3:1:3:14 | A | +| variance.swift:69:38:69:43 | values | Element.Ta | {EXTERNAL LOCATION} | Array | +| variance.swift:69:38:69:43 | values | Element.Ta.Element | variance.swift:69:21:69:21 | T | +| variance.swift:70:16:70:16 | 1 | | {EXTERNAL LOCATION} | Int | +| variance.swift:70:19:70:27 | ArrayLiteral | | {EXTERNAL LOCATION} | Array | +| variance.swift:70:19:70:27 | ArrayLiteral | Element | variance.swift:62:1:64:1 | Shift | +| variance.swift:70:19:70:27 | ArrayLiteral | Element.C | {EXTERNAL LOCATION} | Int | +| variance.swift:70:20:70:24 | Shift | | variance.swift:62:1:64:1 | Shift | +| variance.swift:70:20:70:24 | Shift | C | {EXTERNAL LOCATION} | Int | +| variance.swift:70:20:70:26 | Shift(...) | | variance.swift:62:1:64:1 | Shift | +| variance.swift:70:20:70:26 | Shift(...) | C | {EXTERNAL LOCATION} | Int | +| variance.swift:72:30:72:37 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:72:30:72:37 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:72:30:72:37 | callback | Args.T0 | variance.swift:3:1:3:14 | A | +| variance.swift:72:30:72:37 | callback | Args.T0.Ta | variance.swift:72:25:72:25 | T | +| variance.swift:72:30:72:37 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:73:5:73:28 | boundContraReverseActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:73:5:73:28 | boundContraReverseActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:73:5:73:28 | boundContraReverseActual | Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:73:5:73:28 | boundContraReverseActual | Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:73:5:73:28 | boundContraReverseActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:73:32:73:62 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| variance.swift:73:32:73:62 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:73:32:73:62 | FunctionExpr | Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:73:32:73:62 | FunctionExpr | Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:73:32:73:62 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:73:35:73:39 | value | | variance.swift:5:1:5:21 | B | +| variance.swift:73:35:73:39 | value | Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:73:60:73:60 | 1 | | {EXTERNAL LOCATION} | Int | +| variance.swift:73:60:73:60 | Block | | {EXTERNAL LOCATION} | Int | +| variance.swift:74:40:74:63 | boundContraReverseActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:74:40:74:63 | boundContraReverseActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:74:40:74:63 | boundContraReverseActual | Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:74:40:74:63 | boundContraReverseActual | Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:74:40:74:63 | boundContraReverseActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:76:29:76:36 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:76:29:76:36 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:76:29:76:36 | callback | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:76:29:76:36 | callback | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:76:29:76:36 | callback | Args.T0.Args.T0 | variance.swift:3:1:3:14 | A | +| variance.swift:76:29:76:36 | callback | Args.T0.Args.T0.Ta | variance.swift:76:24:76:24 | T | +| variance.swift:76:29:76:36 | callback | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:76:29:76:36 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args.T0.Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args.T0.Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:5:77:27 | boundDoubleNestedActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:31:77:73 | FunctionExpr | | {EXTERNAL LOCATION} | Function | +| variance.swift:77:31:77:73 | FunctionExpr | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:77:31:77:73 | FunctionExpr | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:77:31:77:73 | FunctionExpr | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:77:31:77:73 | FunctionExpr | Args.T0.Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:77:31:77:73 | FunctionExpr | Args.T0.Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:77:31:77:73 | FunctionExpr | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:31:77:73 | FunctionExpr | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:34:77:41 | callback | | {EXTERNAL LOCATION} | Function | +| variance.swift:77:34:77:41 | callback | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:77:34:77:41 | callback | Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:77:34:77:41 | callback | Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:77:34:77:41 | callback | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:77:71:77:71 | 1 | | {EXTERNAL LOCATION} | Int | +| variance.swift:77:71:77:71 | Block | | {EXTERNAL LOCATION} | Int | +| variance.swift:78:5:78:16 | doubleNested | | {EXTERNAL LOCATION} | Int | +| variance.swift:78:20:78:61 | boundDoubleNested(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | | {EXTERNAL LOCATION} | Function | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args.T0 | {EXTERNAL LOCATION} | Function | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args.T0.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args.T0.Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args.T0.Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Args.T0.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:78:38:78:60 | boundDoubleNestedActual | Return | {EXTERNAL LOCATION} | Int | +| variance.swift:80:34:80:38 | value | | variance.swift:3:1:3:14 | A | +| variance.swift:80:34:80:38 | value | Ta | {EXTERNAL LOCATION} | Function | +| variance.swift:80:34:80:38 | value | Ta.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:80:34:80:38 | value | Ta.Args.T0 | variance.swift:3:1:3:14 | A | +| variance.swift:80:34:80:38 | value | Ta.Args.T0.Ta | variance.swift:80:29:80:29 | T | +| variance.swift:80:34:80:38 | value | Ta.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:81:5:81:32 | boundInvariantFunctionActual | | variance.swift:3:1:3:14 | A | +| variance.swift:81:5:81:32 | boundInvariantFunctionActual | Ta | {EXTERNAL LOCATION} | Function | +| variance.swift:81:5:81:32 | boundInvariantFunctionActual | Ta.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:81:5:81:32 | boundInvariantFunctionActual | Ta.Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:81:5:81:32 | boundInvariantFunctionActual | Ta.Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:81:5:81:32 | boundInvariantFunctionActual | Ta.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:81:36:81:53 | GenericTypeExpr | | variance.swift:3:1:3:14 | A | +| variance.swift:81:36:81:53 | GenericTypeExpr | Ta | {EXTERNAL LOCATION} | Function | +| variance.swift:81:36:81:53 | GenericTypeExpr | Ta.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:81:36:81:53 | GenericTypeExpr | Ta.Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:81:36:81:53 | GenericTypeExpr | Ta.Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:81:36:81:53 | GenericTypeExpr | Ta.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:81:36:81:55 | ...(...) | | variance.swift:3:1:3:14 | A | +| variance.swift:81:36:81:55 | ...(...) | Ta | {EXTERNAL LOCATION} | Function | +| variance.swift:81:36:81:55 | ...(...) | Ta.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:81:36:81:55 | ...(...) | Ta.Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:81:36:81:55 | ...(...) | Ta.Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:81:36:81:55 | ...(...) | Ta.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:82:48:82:75 | boundInvariantFunctionActual | | variance.swift:3:1:3:14 | A | +| variance.swift:82:48:82:75 | boundInvariantFunctionActual | Ta | {EXTERNAL LOCATION} | Function | +| variance.swift:82:48:82:75 | boundInvariantFunctionActual | Ta.Args | {EXTERNAL LOCATION} | Tuple1 | +| variance.swift:82:48:82:75 | boundInvariantFunctionActual | Ta.Args.T0 | variance.swift:5:1:5:21 | B | +| variance.swift:82:48:82:75 | boundInvariantFunctionActual | Ta.Args.T0.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:82:48:82:75 | boundInvariantFunctionActual | Ta.Return | {EXTERNAL LOCATION} | Int | +| variance.swift:84:25:84:29 | value | | {EXTERNAL LOCATION} | Optional | +| variance.swift:84:25:84:29 | value | Wrapped | variance.swift:3:1:3:14 | A | +| variance.swift:84:25:84:29 | value | Wrapped.Ta | variance.swift:84:20:84:20 | T | +| variance.swift:85:5:85:23 | boundOptionalActual | | {EXTERNAL LOCATION} | Optional | +| variance.swift:85:5:85:23 | boundOptionalActual | Wrapped | variance.swift:5:1:5:21 | B | +| variance.swift:85:5:85:23 | boundOptionalActual | Wrapped.Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:85:36:85:41 | GenericTypeExpr | | variance.swift:5:1:5:21 | B | +| variance.swift:85:36:85:41 | GenericTypeExpr | Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:85:36:85:43 | ...(...) | | variance.swift:5:1:5:21 | B | +| variance.swift:85:36:85:43 | ...(...) | Tb | {EXTERNAL LOCATION} | Int | +| variance.swift:86:5:86:12 | optional | | {EXTERNAL LOCATION} | Int | +| variance.swift:86:16:86:49 | boundOptional(...) | | {EXTERNAL LOCATION} | Int | +| variance.swift:86:30:86:48 | boundOptionalActual | | {EXTERNAL LOCATION} | Optional | +| variance.swift:86:30:86:48 | boundOptionalActual | Wrapped | variance.swift:5:1:5:21 | B | +| variance.swift:86:30:86:48 | boundOptionalActual | Wrapped.Tb | {EXTERNAL LOCATION} | Int | testFailures diff --git a/unified/ql/test/library-tests/type-inference/variance-bounds.expected b/unified/ql/test/library-tests/type-inference/variance-bounds.expected new file mode 100644 index 000000000000..98483f404c69 --- /dev/null +++ b/unified/ql/test/library-tests/type-inference/variance-bounds.expected @@ -0,0 +1,16 @@ +bounds +| boundDoubleActual | T | lower | | Int | +| boundDoubleNestedActual | T | equality | | Int | +| boundInvariantActual | T | equality | | Int | +| boundLowerActual | T | lower | | Int | +| boundMixedActual | T | lower | | String | +| boundMixedActual | T | upper | | Int | +| boundNestedActual | T | equality | | Int | +| boundOptionalActual | T | equality | | Int | +| boundShiftActual | T | equality | | Int | +| boundUpperActual | T | upper | | Int | +noBounds +| boundContraReverseActual | +| boundInvariantConversionActual | +| boundInvariantFunctionActual | +| boundWrongDirectionActual | diff --git a/unified/ql/test/library-tests/type-inference/variance-bounds.ql b/unified/ql/test/library-tests/type-inference/variance-bounds.ql new file mode 100644 index 000000000000..09fb265494d0 --- /dev/null +++ b/unified/ql/test/library-tests/type-inference/variance-bounds.ql @@ -0,0 +1,49 @@ +import codeql.unified.internal.typeinference.Type +import codeql.unified.internal.typeinference.TypeMention +import codeql.unified.internal.typeinference.TypeInference + +private class Actual extends Identifier { + Actual() { + this.getValue().matches("bound%Actual") and + this.getFile().getBaseName() = "variance.swift" and + exists(inferType(this, TypePath::nil())) + } + + Type getTypeAt(TypePath path) { result = inferType(this, path) } +} + +private module Input implements VarianceMatchingInputSig { + predicate relevantConstraint(Actual actual, TypeMention constraint) { + exists(actual) and + constraint = + any(FunctionDeclaration f | + actual.getValue() = f.getName() + "Actual" and f.getFile().getBaseName() = "variance.swift" + ).getParameter(0).getType() + } +} + +private module Match = VarianceMatching; + +query predicate bounds(string name, string parameter, string relationName, string path, string type) { + exists( + Actual actual, TypeMention constraint, TypeParameter tp, TypePath p, Type t, + MatchingRelation relation + | + Match::typeBound(actual, constraint, tp, relation, p, t) and + name = actual.getValue() and + parameter = tp.toString() and + ( + relation.isCovariant() and relationName = "lower" + or + relation.isContravariant() and relationName = "upper" + or + relation.isInvariant() and relationName = "equality" + ) and + path = TypePath::printTypePathVerbose(p) and + type = t.toString() + ) +} + +query predicate noBounds(string name) { + exists(Actual actual | name = actual.getValue() and not Match::typeBound(actual, _, _, _, _, _)) +} diff --git a/unified/ql/test/library-tests/type-inference/variance.swift b/unified/ql/test/library-tests/type-inference/variance.swift index 11d19d3b6054..ca2e6e2c6fcd 100644 --- a/unified/ql/test/library-tests/type-inference/variance.swift +++ b/unified/ql/test/library-tests/type-inference/variance.swift @@ -1,4 +1,4 @@ -// variance is not currently supported +// Recursive variance through function inputs, outputs, and generic constructors. class A {} @@ -10,10 +10,77 @@ func foo(f: (B) -> A) -> (T1, T2) { let lam = { (a: A) -> B in B() } // $ target=A.init -let x = foo(f: lam) // $ target=foo $ MISSING: type=x@Tuple2:Int type=x@Tuple2:String +let x = foo(f: lam) // $ target=foo type=x@Tuple2:Int type=x@Tuple2:String func bar() -> B { B() } // $ target=A.init func baz() { - let x: A = bar() // $ target=bar $ MISSING: type=bar(...)@B:Int + let x: A = bar() // $ target=bar type=bar(...)@B:Int } + +func boundLower(_ value: [T]) -> T { fatalError() } +let boundLowerActual = [1] +let lower = boundLower(boundLowerActual) // $ target=boundLower type=lower:Int + +func boundUpper(_ callback: (T) -> Int) -> T { fatalError() } +let boundUpperActual = { (value: Int) -> Int in value } // $ type=value:Int +let upper = boundUpper(boundUpperActual) // $ target=boundUpper type=upper:Int + +func boundDouble(_ callback: ((T) -> Int) -> Int) -> T { fatalError() } +let boundDoubleActual = { (callback: (Int) -> Int) -> Int in callback(1) } // $ target=Function.callAsFunction +let double = boundDouble(boundDoubleActual) // $ target=boundDouble type=double:Int + +func boundInvariant(_ value: A) -> T { fatalError() } +let boundInvariantActual = A() // $ target=A.init +let invariant = boundInvariant(boundInvariantActual) // $ target=boundInvariant type=invariant:Int + +func boundNested(_ value: [A]) -> T { fatalError() } +let boundNestedActual = [B()] // $ target=A.init +let nested = boundNested(boundNestedActual) // $ target=boundNested type=nested:Int + +// Neither reversing a covariant conversion nor converting through an invariant +// parameter can establish a bound. These calls intentionally have incompatible types. +func boundWrongDirection(_ value: [B]) -> T { fatalError() } +let boundWrongDirectionActual = [A()] // $ target=A.init +let wrongDirection = boundWrongDirection(boundWrongDirectionActual) // $ target=boundWrongDirection + +func boundInvariantConversion(_ value: A>) -> T { fatalError() } +let boundInvariantConversionActual = A>() // $ target=A.init +let invariantConversion = boundInvariantConversion(boundInvariantConversionActual) // $ target=boundInvariantConversion + +func boundContext(_ first: T, _ values: [A]) {} +boundContext(1, [B()]) // $ target=boundContext target=A.init type=B(...)@B:Int + +func boundAlternatives(_ first: [T], _ second: [T]) -> T { fatalError() } +let alternatives = boundAlternatives([1], ["x"]) // $ target=boundAlternatives type=alternatives:Int type=alternatives:String + +// Keep lower and upper bounds distinct, without solving their inconsistency. +func boundMixed(_ callback: (T) -> T) -> T { fatalError() } +let boundMixedActual = { (value: Int) -> String in "x" } +let mixed = boundMixed(boundMixedActual) // $ target=boundMixed type=mixed:Int type=mixed:String + +class Shift: A<[C]> { + override init() { super.init() } // $ target=A.init +} +func boundShift(_ value: [A<[T]>]) -> T { fatalError() } +let boundShiftActual = [Shift()] // $ target=Shift.init +let shifted = boundShift(boundShiftActual) // $ target=boundShift type=shifted:Int + +func shiftedContext(_ first: T, _ values: [A<[T]>]) {} +shiftedContext(1, [Shift()]) // $ target=shiftedContext target=Shift.init type=Shift(...)@Shift:Int + +func boundContraReverse(_ callback: (A) -> Int) -> T { fatalError() } +let boundContraReverseActual = { (value: B) -> Int in 1 } +let contraReverse = boundContraReverse(boundContraReverseActual) // $ target=boundContraReverse + +func boundDoubleNested(_ callback: ((A) -> Int) -> Int) -> T { fatalError() } +let boundDoubleNestedActual = { (callback: (B) -> Int) -> Int in 1 } +let doubleNested = boundDoubleNested(boundDoubleNestedActual) // $ target=boundDoubleNested type=doubleNested:Int + +func boundInvariantFunction(_ value: A<(A) -> Int>) -> T { fatalError() } +let boundInvariantFunctionActual = A<(B) -> Int>() // $ target=A.init +let invariantFunction = boundInvariantFunction(boundInvariantFunctionActual) // $ target=boundInvariantFunction + +func boundOptional(_ value: A?) -> T { fatalError() } +let boundOptionalActual: B? = B() // $ target=A.init +let optional = boundOptional(boundOptionalActual) // $ target=boundOptional type=optional:Int