Skip to content

Commit 7585709

Browse files
committed
Start stubbing out more parts of Type::join().
Improve support for Optional among other things. Return Any when it is really the best answer given the types involved, or nullptr if we cannot yet produce an accurate result. This implementation returns Any? when joining Any with an Optional<T>. In our type system both Any and Any? are effectively subtypes of one another since each can hold all the values that the other can hold. So this choice is somewhat arbitrary, but does line up nicely with the notion that T is always a subtype of T?.
1 parent 3992a8c commit 7585709

File tree

5 files changed

+268
-119
lines changed

5 files changed

+268
-119
lines changed

include/swift/AST/Type.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,19 @@ class Type {
368368
/// class D { }
369369
/// \endcode
370370
///
371-
/// The join of B and C is A, the join of A and B is A. However, there is no
372-
/// join of D and A (or D and B, or D and C) because there is no common
373-
/// superclass. One would have to jump to an existential (e.g., \c AnyObject)
374-
/// to find a common type.
371+
/// The join of B and C is A, the join of A and B is A.
372+
///
373+
/// The Any type is considered the common supertype by default when no
374+
/// closer common supertype exists.
375+
///
376+
/// In unsupported cases where we cannot yet compute an accurate join,
377+
/// we return None.
375378
///
376379
/// \returns the join of the two types, if there is a concrete type
377380
/// that can express the join, or Any if the only join would be a
378-
/// more-general existential type
379-
static Type join(Type first, Type second);
381+
/// more-general existential type, or None if we cannot yet compute a
382+
/// correct join but one better than Any may exist.
383+
static Optional<Type> join(Type first, Type second);
380384

381385
private:
382386
// Direct comparison is disabled for types, because they may not be canonical.

0 commit comments

Comments
 (0)