correct location for generic parameters that cannot be inferred. The cases that
I thought were incorrectly rejected on first glance were actually correct.
to remap an unbound generic type into a bound generic type. This shares
a common codepath to make way for future progress.
This exposed a case where we'd produce invalid ASTs in some testcases
in the validation tests because started asserting on the invalid code.
Solve this by detecting the problem and producing a circularity error.
Overall, NFC.
A computed property might have a getter and setter but no materializeForSet;
synthesize the decl so that we can emit a witness thunk and reference it
from the default witness table.
Default witnesses for storage is not quite hooked up yet, so this is NFC
for now.
Otherwise, we hit a problem because the setter is called with self passed as a
(single retainable pointer) value, but the witness expects a self value passed
indirectly.
I hit this while testing other stuff related to resilient default implementations.
in arbitrary places. This fixes a regression caught by SR-770 that
would otherwise be introduced by us removing automatic currying syntax,
it allows the use of @noescape on typealiases (resolving SR-824),
allows @noescape on nested function types (fixing rdar://19997680)
and allows @noescape to be used on local variables (fixing
rdar://19997577).
At this point, @noescape should stop being a decl attribute, but I'll bring
that up on swift-evolution.
Try to match the original spelling of static/class in diagnostics and
when printing the AST. Also fixes cases with
PrintOptions.PrintImplicitAttrs = false, where we would just print
'class', which was not valid code.
Now that WitnessChecker is separate from ConformanceChecker, implement
a DefaultWitnessChecker subclass which performs default witness
resolution.
This populates the recently-added ProtocolDecl::DefaultWitnesses map.
Unlike ConformanceChecker, the DefaultWitnessChecker looks up the witness
in any protocol extensions of the protocol, matching the context archetypes
of the requirement against the witness.
For now, we infer default witnesses for all protocols, but don't do
anything with that information. An upcoming SILGen patch will start to
emit thunks and add tests.
With this change the base expression of the subscript (beeing already
revalidated earlier in the function) is passed to diagnoseUnviableLookupResults
to emit a fitting diagnostic.
In member ref expressions, if the base is optional, and the expected
expression result is either optional or unknown, suggest a fixit that
makes it into an optional chain expr rather than force unwrapping.
Since in many cases the actual fixit is emitted during diagnosis, and
thus, while type checking sub exprs with no contextual type specified
(so nothing to check for preferring optionality), we also need an
additional flag to pass down from FailureDiagnosis for whether we
prefer to fix as force unwrapping or optional chaining.
I attempted to do this same job via providing a convert type but
setting the ConvertTypeIsOnlyAHint flag on the type checker, but
unfortunately there are a lot of other moving parts that look at that
type, even if it is only supposed to be a hint, so an additional flag
to the CS ended up being cleaner.
Allow a behavior protocol to declare an `initStorage` implementation with a parameter. If we have an initializer expression, use `initStorage(initExpr)` to initialize the storage; otherwise, remember the storage declaration and its initializer. Definite
initialization will have to use these to insert the initialization operation for the behavior property at the right place.
The domain constant generated by PrintAsObjC always has the value
`"ModuleName.TypeName"`, but the actual value of the derived
`_NSErrorDomain` constant from the `_BridgedNSError` protocol was
implemented as `"\(self)"`. This meant that any time that the default
string representation of the enum type did not match the format
`"ModuleName.TypeName"`, the generated domain constant did not match the
actual error domain. This could happen when compiling programs at the
command-line that define the error (as the module name is typically
omitted there), or if the enum was nested inside another @objc
declaration (as the qualified type name there includes the parent type
declaration).
Fixes SR-700.
Passing a function type to an @autoclosure param would always fail to
type check because of the attempt to decompose the parallel structure
of the two (both being functions). In this case, though, we don’t want
to do any such thing, we want to allow the ExprRewriter to explicitly
insert an AutoClosureExpr in coerceToType, as it would do with any
other non-function arg type.
With resilient protocols, we have to emit a default witness table
for SILGen, independent of any one conformance.
This patch introduces a WitnessChecker base class, which contains
parts of the ConformanceChecker responsible for lookup and matching
of witnesses.
A default witness lookup will be performed inside the protocol's
DeclContext in order to find extension methods, without opening any
associated types.
We had four duplicated implementations of checking how a protocol
requirement uses 'Self', all slightly wrong or incomplete:
- When deciding if the protocol type can be used as an existential.
This one would just ignore 'Self' in the return type of a method
completely, which was incorrect for cases where 'Self' is
contravariant but part of the return value, for example:
func foo() -> (Self -> ())
- When deciding if a member access can be performed on an existential
value. This is distinct from the former, because the member may
have been defined in a protocol extension, in which case it cannot
be used even if the protocol type can be used as an existential.
Unfortunately, this implementation was overly conservative, and
would reject uses of 'Self' where Sema could in fact erase the
existential type, for example:
func foo() -> Self??
func foo() -> Self.Type
func foo() -> (Self, Self)
This function handled function return types correctly, effectively
plugging the leak in the previous code. It did lead to inconsistent
behavior with protocols that had contravariant Self in requirements
though; sometimes we would diagnose uses of the existential type,
other times we would only complain about specific members.
- When deciding if a method in a non-final class can model a protocol
requirement. This one was the most elaborate one, but here
contravariance and uses of associated types are actually okay, so
it was written to pick up covariant 'Self' only. However, it also
did not handle metatypes and tuples.
- When opening the type of member of an existential, we would check
if the return value was 'Self' or an optional of 'Self', but again
this check was too conservative, so after the previous three were
fixed, we could reference members on existentials that did not
have a correct opened type.
Now, these have been combined into one check. To fix some crashes,
Sema's implementation of erasing existentials now relies on
coerceToType() instead of hand-rolling a few coercions of its own,
and wrapping the rest in CovariantFunctionConversionExpr, which
didn't make much sense if the result was not a function type.
SILGen still does not support function type conversions where an
existential return value is being erased; these would silently
miscompile before, but crash with an assertion now, because they
are correctly modeled as a FunctionConversionExpr, and not
CovariantFunctionConversionExpr.
Previously we would produce:
t.swift:3:3: error: binary operator '+=' cannot be applied to operands of type 'Int' and '_'
a += a + b
~ ^ ~~~~~
with a candidate set to follow. Now we properly match up the inout/lvalue type and produce
the following more specific diagnostic:
t.swift:3:10: error: cannot convert value of type 'UInt32' to expected argument type 'Int'
a += a + b
^
pointing the the "b".
A catch block can only be entered if the do block threw an error. In a
rethrows function, if the do block throws an error only under rethrows
conditions, then the catch block can only be entered under rethrows
conditions, which means the catch block can unconditionally throw and
it's still safe.
This enables code that looks like
```swift
func foo(f: () throws -> Void) rethrows {
do {
try f()
} catch is SomeError {
throw OtherError()
}
}
```
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.
PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.