In the single-element case, it is treated as the dictionary key.
func takesDict(_ x: [Int: String]) {}
takesDict([]) // diagnose with fixit to add missing ':'
takesDict([1]) // diagnose with fixit to add missing ': <#value#>'
takesDict([foo.<complete>]) // prioritise Int members in completion results -
// the user just hasn't written the value yet.
The above previously failed with a generic mismatch error in normal type
checking (due to the literal being parsed as an array literal) and code
completion could not pick up the expected type from the context.
If AST node is a reference to an invalid declaration let's
diagnose it as such unless some errors have been emitted
(invalid declaration itself should have a diagnostic
describing a reason why it's invalid).
It was used for unresolved member and `.dynamicType` references
as well as a couple of other places, but now unresolved member
references no longer need that due to new implicit "chain result"
AST node and other places could use more precise locators
e.g. new `.dynamicType` locator or `sequence element` for `for in`
loops.
func foo(a: Int, b: Int) {}
func foo(a: String) {}
// Int and String should both be valid, despite the missing argument for the
// first overload since the second arg may just have not been written yet.
foo(a: <complete here>
func bar(a: (Int) -> ()) {}
func bar(a: (String, Int) -> ()) {}
// $0 being of type String should be valid, rather than just Int, since $1 may
// just have not been written yet.
bar { $0.<complete here> }
This check did not handle MemberRefExprs with an InOutExpr base,
giving it inconsistent behavior:
- With a class, we would diagnose self-assignment of computed
properties
- With a struct, accesses to computed properties would build a
MemberRefExpr with an InOutExpr base, so self-assignments
were *not* diagnosed.
Let's tweak the check to consistently diagnose self-assignments
to stored properties only, instead of the emergent behavior
as described above.
This method had a messy contract:
- Setting the diags parameter to nullptr inhibited caching
- The initExpr out parameter could only used if no result
had yet been cached
Let's instead use the request evaluator here.
Rework the data structures we use in the conformance checker to talk
about missing witnesses, so they can capture the set of potential
matches. This will allow us to delay more diagnostics to later,
more uniformly.
The lack of these functions in a function builder is diagnosed in
different places in the type checker. Extend these diagnostics to
provide stubs in the function builder.
Thanks to Suyash for the suggestion!
When performing code completion inside the declaration of a type with
the function builder attribute, also include completions for all of
the possible "build" functions.
When a use of a function builder involves a statement kind that the
function builder doesn't support (e.g., if-else), add a note to the
diagnostic that specifies what methods need to be added to the
function builder to support that statement, including Fix-Its with
stub implementations.
* [AST] Add 'FloatingPoint' known protocol kind
* [Sema] Emit a diagnostic for comparisons with '.nan' instead of using '.isNan'
* [Sema] Update '.nan' comparison diagnostic wording
* [Sema] Explicitly check for either arguments to be '.nan' and tweak a comment
* [Test] Tweak some comments
* [Diagnostic] Change 'isNan' to 'isNaN'
* [Sema] Fix a bug where firstArg was checked twice for FloatingPoint conformance and update some comments
* [Test] Fix comments in test file
* [NFC] Add a new 'isStandardComparisonOperator' method to 'Identifier' and use it in ConstraintSystem
* [NFC] Reuse argument decl extraction code and switch over to the new 'isStandardComparisonOperator' method
* [NFC] Update conformsToKnownProtocol to accept DeclContext and use it to check for FloatingPoint conformance
We previously were not properly handling the diagnostics for using an rvalue implicit member on the left hand side of an assignment. This adds the proper handling and extends it for member chains.
Move the analysis and transformation of unresolved member chains into the PreCheckExpression pass in order to make sure that contextual types get hooked up properly before we actually begin generating constraints.
The old method of generating this placeholder expression caused issues when constraints had to be recursively regenerated during solving. Now, we generate UnresolvedMemberChainResultExprs in walkToExprPre, and use ASTWalker::Parent instead of ConstraintSystem::getParentExpr to find the parent of the chain tail.
This also lets us generate the chain constraints as part of the normal ConstraintGenerator visit, rather than as an extra walkToExprPost step.