summaryrefslogtreecommitdiff
path: root/source/slang/slang-lookup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-lookup.cpp')
-rw-r--r--source/slang/slang-lookup.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp
index b54b09d63..c50364201 100644
--- a/source/slang/slang-lookup.cpp
+++ b/source/slang/slang-lookup.cpp
@@ -636,6 +636,63 @@ static void _lookUpMembersInSuperTypeImpl(
_lookUpMembersInSuperType(astBuilder, name, leafType, interfaceType, leafIsInterfaceWitness, request, ioResult, inBreadcrumbs);
}
+ else if( auto andType = as<AndType>(superType) )
+ {
+ // We have a type of the form `leftType & rightType` and we need to perform
+ // lookup in both `leftType` and `rightType`.
+ //
+ auto leftType = andType->left;
+ auto rightType = andType->right;
+
+ // Operationally, we are in a situation where we have a witness
+ // that the `leafType` we are doing lookup on is an subtype
+ // of `superType` (which is `leftType & rightType`) and now we need
+ // to construct a witness that `leafType` is a subtype of
+ // the `Left` type.
+ //
+ // Effectively, we have a witness that `T : X & Y` and we
+ // need to extract from it a witness that `T : X`.
+ // Fortunately, we have a class of subtype witness that does
+ // *precisely* this:
+ //
+ auto leafIsLeftWitness = astBuilder->create<ExtractFromConjunctionSubtypeWitness>();
+ //
+ // Our witness will be to the fact that `leafType` is a subtype of `leftType`
+ //
+ leafIsLeftWitness->sub = leafType;
+ leafIsLeftWitness->sup = leftType;
+ //
+ // The evidence for the subtype relationship will be a witness
+ // proving that `leafType : leftType & rightType`:
+ //
+ leafIsLeftWitness->conunctionWitness = leafIsSuperWitness;
+ //
+ // ... along with the index of the desired super-type in
+ // that conjunction. The index of `leftType` in `leftType & rightType`
+ // is zero.
+ //
+ leafIsLeftWitness->indexInConjunction = 0;
+
+ // The witness for the fact that `leafType : rightType` is the
+ // same as for the left case, just with a different index into
+ // the conjunction.
+ //
+ auto leafIsRightWitness = astBuilder->create<ExtractFromConjunctionSubtypeWitness>();
+ leafIsRightWitness->conunctionWitness = leafIsSuperWitness;
+ leafIsRightWitness->indexInConjunction = 1;
+ leafIsRightWitness->sub = leafType;
+ leafIsRightWitness->sup = rightType;
+
+ // We then perform lookup on both sides of the conjunction, and
+ // accumulate whatever items are found on either/both sides.
+ //
+ // For each recursive lookup, we pass the appropriate pair of
+ // the type to look up in and the witness of the subtype
+ // relationship.
+ //
+ _lookUpMembersInSuperType(astBuilder, name, leafType, leftType, leafIsLeftWitness, request, ioResult, inBreadcrumbs);
+ _lookUpMembersInSuperType(astBuilder, name, leafType, rightType, leafIsRightWitness, request, ioResult, inBreadcrumbs);
+ }
}
/// Perform lookup for `name` in the context of `type`.