Commit Graph

763 Commits

Author SHA1 Message Date
Holly Borla
522eedcfd1 [ConstraintSystem] Emit an error message when trying to pass a property
wrapper projection argument to a wrapped parameter with arguments in the
wrapper attribute.
2021-02-25 18:35:14 -08:00
Holly Borla
ea3fe03c98 [Property Wrappers] Add a constraint fix and diagnostic for the case
where the programmer tries to pass a projection argument to a wrapped
parameter without 'var projectedValue'.
2021-02-25 18:35:14 -08:00
Pavel Yaskevich
cf5e1fff8d [Diagnostics] Add a tailored diagnostic for contextual lookup on protocols without Self requirement 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
2d8f002299 [CSDiagnostics] Adjacent diagnostics for the new rules of static member lookup in generic context 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
e548366bb5 [TypeChecker] Add tests for static member refs on protocol metatypes feature 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
feb8684dac [Diagnostics] Add a clarifying note about result type for invalid member ref diagnostic 2021-02-23 11:33:10 -08:00
Pavel Yaskevich
03d869ad8b [Diagnostics] Extract invalid result type from overload choice
Instead of threading it through the constraint system all the way
to a diagnostic, let's extract it from overload choice instead.
2021-02-23 11:33:10 -08:00
Pavel Yaskevich
9231acf202 [Diagnostics] Implement a tailored diagnostic for invalid static member refs on protocol metatypes 2021-02-23 11:32:24 -08:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Luciano Almeida
d55eed46e8 [Sema][CSApply] Moving some checked cast diagnostics to a fix format (#34980)
* [Sema] Implementing is runtime check always true diagnostic as a fix

* [AST] Implement getWithoutThrows on function type

* [CSSimplify] Detect that checked cast types conversion is always true and record warning fix

* [test] Some additional test cases for SR-13789

* [Sema] Fixing typo on fix name

* [Sema] Move and adjust the ConditionalCast diagnostics to the fix format

* [Sema] Remove some checked cast diagnostics from check constraints and move to fix

* [Sema] Renaming checked cast coercible types fix

* [Sema] Some adjustments and rewrite on the logic for downcast record fix

* [Sema] Move logic of runtime function type to AllowUnsupportedRuntimeCheckedCast::attempt

* [Sema] Abstract checked cast fix logic to static function and minor adjustments

* [Sema] Renamings from review
2021-02-10 08:31:06 -03:00
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
Pavel Yaskevich
e086896f24 [Diagnostics] Avoid adding comma when reordering with last argument 2021-01-19 13:37:43 -08:00
Pavel Yaskevich
09f3461e3d [Diagnostics] Adjust OoO fix-it intervals to account for replacement of first argument
Current logic fix-it didn't account for the first argument being re-ordered.
The start position for the first argument should always be the next token
after left paren denoting a start of the argument list.

Resolves: rdar://problem/70764991
2021-01-19 13:37:32 -08:00
Pavel Yaskevich
5f20eb661e [Diagnostics] Adjust requirement failures to retrieve conformance information from locator
Conditional conformances previously relied on `CheckedConformances`
cache to retrieve information about conditional requirements from
base conformance, but that is not really necessary anymore since
`ConformanceRequirement` element could provide all required info.
2021-01-08 12:55:14 -08:00
Pavel Yaskevich
f0ff68e707 [Diagnostics] Special case requirement failures related to return statement/expression
Make sure that "affected" declaration is recognized as the one
to which result type is attached to if the requirement failure
is originated in contextual type of `return` statement/expression.

Resolves: SR-13992
Resolves: rdar://72819046
Resolves: rdar://57789606
2021-01-06 12:47:37 -08:00
Pavel Yaskevich
4917d4314b [ConstraintSystem] Use new ConformanceRequirement to record checked conformances and conditional requirements 2021-01-06 11:01:35 -08:00
Pavel Yaskevich
ec31d77fa6 [Diagnostics] Allow integer cast fix-its for assignment mismatches 2020-12-11 20:49:54 -08:00
Luciano Almeida
c8ea08df78 [Sema] Creating ambiguous base for none member warning diagnostic as a fix 2020-12-05 22:48:09 -03:00
Doug Gregor
50cdddaf95 [Concurrency] Enable implicit conversion from synchronous -> asynchronous. 2020-12-03 12:44:21 -08:00
Pavel Yaskevich
85181360b1 Merge pull request #34810 from xedin/rdar-66709164
[ConstraintSystem] Detect and diagnose extraneous return(s) in result build body
2020-12-02 15:51:10 -08:00
Luciano Almeida
ac65e6fcc4 [Sema] Detect if we should use a conditional binding when recording the CoerceToCheckedCast fix 2020-12-01 09:03:17 -03:00
Luciano Almeida
7df08f808d [Sema][test] Add SR-13899 test cases 2020-11-28 18:20:37 -03:00
Luciano Almeida
1479c0001f [Sema] Detach did you mean from error missing force downcast diagnostic moving to note 2020-11-28 18:16:07 -03:00
Pavel Yaskevich
03ede7427c [Diagnostics] Diagnose use of one or more return statements in a result builder body 2020-11-19 17:21:00 -08:00
Nathan Hawes
edbbefce91 [CodeCompletion][Sema] Add fix to treat empty or single-element array literals as dictionaries when used as such
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.
2020-11-11 11:48:39 -08:00
Pavel Yaskevich
409aa35312 [Diagnostic] Add a diagnostic for invalid declaration refs
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).
2020-11-04 12:15:45 -08:00
Pavel Yaskevich
9384813b49 [Diagnostics] Split "only concrete types conform to protocols" into a separate note 2020-10-27 14:52:23 -07:00
Pavel Yaskevich
1683fb91b6 [ConstraintSystem] Remove RValueAdjustment locator element
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.
2020-10-26 00:40:45 -07:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Nathan Hawes
15f5222bbd [CodeCompletion][Sema] Allow missing args when solving if the completion location indicates the user may intend to write them later.
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> }
2020-10-19 12:16:19 -07:00
Pavel Yaskevich
461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Luciano Almeida
6ceda75414 [CSDiagnostic] Minor code improvement on MissingGenericArgumentsFailure addressing fixme 2020-10-04 16:19:06 -03:00
Pavel Yaskevich
4d0ab13c36 Merge pull request #34089 from xedin/nil-as-a-hole
[Diagnostics] Diagnose cases when it's impossible to infer type for `nil` literal
2020-09-28 12:13:25 -07:00
Slava Pestov
2fb3c7c975 Merge pull request #34092 from slavapestov/didset-access-semantics-cycle
Sema: Simplify adjustSelfTypeForMember() a little bit to avoid a cycle
2020-09-26 10:15:52 -04:00
Slava Pestov
d5febdb791 Sema: Fix diagnoseSelfAssignment() with computed properties
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.
2020-09-26 00:02:42 -04:00
Pavel Yaskevich
f96d6d3486 [Diagnostics] Remove obsolete special case for _ = nil 2020-09-25 15:56:18 -07:00
Pavel Yaskevich
1fb69a7d43 [Diagnostics] Diagnose cases when it's impossible to infer type for nil
Detect and diagnose situations when it's invalid to use `nil`
literal without more context e.g. `_ = nil`, `nil as? Int`, or
`_ = nil!`.
2020-09-25 14:59:54 -07:00
Slava Pestov
dcafd585c1 Sema: Use ASTScope::lookupSingleLocalDecl() in MissingOptionalUnwrapFailure 2020-09-25 17:59:20 -04:00
Slava Pestov
29ce77209c AST: Convert ConstructorDecl::getDelegatingOrChainedInitKind() into a request
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.
2020-09-25 17:59:20 -04:00
Doug Gregor
1c5be70255 Merge pull request #33995 from DougGregor/conformance-checker-missing-witnesses
[Conformance checker] Capture potential matches for missing witnesses.
2020-09-18 20:31:35 -07:00
Doug Gregor
f91767cfa0 [Conformance checker] Capture potential matches for missing witnesses.
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.
2020-09-18 16:50:22 -07:00
Doug Gregor
3b8656dc6f [Function builders] Add stubs for missing buildBlock and buildLimitedAvailability
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!
2020-09-16 16:31:03 -07:00
Doug Gregor
20ab640e56 [Function builders] Add code completion for build* functions.
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.
2020-09-16 11:55:09 -07:00
Doug Gregor
19cfe21db8 [Function builders] Add Fix-Its for missing build* members in builders.
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.
2020-09-15 22:32:21 -07:00
Suyash Srijan
49e7c6126c [Diagnostics] Diagnose comparisons with '.nan' and suggest using '.isNan' instead (#33860)
* [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
2020-09-09 22:08:42 +01:00
Holly Borla
3332df6f89 Merge pull request #33777 from hborla/rename-storage-wrapper
[NFC][Property Wrappers] Rename "storage wrapper var" to "projection var/projected value"
2020-09-03 18:29:04 -07:00
Luciano Almeida
ccdbb0ed6a Merge pull request #33772 from LucianoPAlmeida/correcting-source-location-keypath-fix
[CSDiagnostics] Ensure fix-it inserts uses correct location in infered key path root optional unwrapped
2020-09-03 17:31:39 -03:00
Holly Borla
3fd882cadf [NFC] Rename "storage wrapper var" to "projection var" or "projected value"
in property wrapper-related code.
2020-09-02 18:07:40 -07:00
Luciano Almeida
ed7e03b21b [CSDiagnostics] Ensure fix-it inserts uses correct location in infered key path root optional unwrapped 2020-09-02 19:27:05 -03:00