Commit Graph

2190 Commits

Author SHA1 Message Date
Suyash Srijan
d3b5996b05 [Sema] Diagnose explicit access to a lazy variable's underlying storage (#33144) 2020-07-28 19:12:53 +01:00
Suyash Srijan
db53fc7eb8 [Sema] Diagnose wrapped property if its projected value property conflicts with lazy variable storage property (#33152) 2020-07-28 15:39:49 +01:00
Suyash Srijan
cc49c6105c [Diagnostics] Update diagnostic message for invalid overrides (#33097)
* [Diagnostics] Update 'does not override' diagnostic message to include protocol context as well

* [Sema] Check whether the override context is a class or a protocol for diagnostic purposes

* [Test] Update tests with new diagnostic message for overrides in protocol context

* [Sema] Adjust diagnostic for overrides in structs and enums to use the existing 'override_nonclass_decl' diagnostic
2020-07-27 15:15:28 +01:00
Hamish Knight
da998bae6d Merge pull request #33037 from hamishknight/to-no-avail 2020-07-22 12:19:06 -07:00
Holly Borla
bd03c47506 Merge pull request #33025 from hborla/repair-via-unwrap-typevar
[Property Wrappers] Fix property wrapper initialization type checking when `wrappedValue` is an optional of a generic parameter.
2020-07-22 11:54:17 -07:00
Hamish Knight
be607d15b3 [CS] Introduce performSyntacticDiagnosticsForTarget
Add a function that deals with invoking syntactic
diagnostics for all the expressions involved in
a SolutionApplicationTarget.

Resolves SR-13260
Resolves rdar://65903005
2020-07-21 15:51:07 -07:00
Holly Borla
3b917729dc [Property Wrappers] Always anchor the equality constraint between
the property type and wrapped value type at the wrapped VarDecl.
2020-07-21 15:23:24 -07:00
Robert Widmann
8a7a1d98f5 Teach the VarDeclUsageChecker About Variables Bound in Patterns
The VDUC was missing a class of AST nodes that can bind variables:
patterns in switch statements. For these, it was falling back to
requesting a simple replacement of the bound variable name with _. But
for patterns, this means there's a two-step dance the user has to go
through where the first fixit does this:

.pattern(let x) -> .pattern(let _)

Then a second round of compilation would emit a fixit to do this:

.pattern(let _) -> .pattern(_)

Instead, detect "simple" variable bindings - for now, variable patterns
that are immediately preceded by a `let` or `var` binding pattern - and
collapse two steps into one.

Resolves rdar://47240768
2020-07-21 12:33:14 -07:00
Nikhil
6428c1f9bb [Diagnostic] Fix diagnostic when checking conformance for IUO of gene… (#32987)
* [Diagnostic] Fix diagnostic when checking conformance for IUO of generic parameter

Prints TypeRepr in diagnostic if possible to throw
accurate diagnostic for IUO conformance checking
Fixes [rdar://problem/64953106]. Fixes SR-13119

* Nested name lookup tests update

Name lookup will see the innermost name anyway and
preferred over fully qualified name. Hence the test
cases are also updated.

* Replaced a letter in test case that inadvertently got added

* Code format, corrections and better comments

This commit includes better comments for easy
understanding, formatted the bug fix code with
clang-format and fixes wrong variables inadvertently
introduced.

* [Test] Update type in struct codable test

This commit changes diagnostic type from error type
to Int. Although this diagnostic updated is incorrect, this will
be resolved when 32371 gets pulled.
2020-07-21 09:07:44 -07:00
Pavel Yaskevich
a907a15df9 Merge pull request #32821 from xedin/improve-typevar-bindings
[CSBindings] Split type variable binding inference into phases
2020-07-16 15:51:38 -07:00
Pavel Yaskevich
7ce37dd14d [TypeChecker] NFC: Adjust test-cases improved by changes in binding inference 2020-07-15 20:50:50 -07:00
Anthony Latsis
19f27d9c94 Merge pull request #32752 from AnthonyLatsis/plus-inference
AssociatedTypeInference: Delay substitutions into abstract type witnesses until after they have been computed
2020-07-15 17:27:26 +03:00
Suyash Srijan
0aabee59d6 [Typechecker] Emit specialized diagnostic notes on automatic synthesis failure to Comparable (#32797) 2020-07-14 22:03:08 +01:00
Anthony Latsis
54ccdc67e7 AssociatedTypeInference: Delay substitutions into abstract type witnesses until after they have been computed 2020-07-12 02:55:22 +03:00
Slava Pestov
a689dd2d87 Merge pull request #32761 from slavapestov/typealias-member-reference-nonsense
Sema: Don't look through nested typealiases when checking for unsupported member reference
2020-07-09 09:36:46 -04:00
Slava Pestov
1802ec9b20 Merge pull request #32753 from theblixguy/fix/associated-type-inference-enum-witness
[AssociatedTypeInference] Strip 'self' parameter from function type of an enum case witness
2020-07-08 19:15:41 -04:00
Slava Pestov
b614a4d335 Sema: Don't look through nested typealiases when checking for unsupported member reference
It appears that a long time ago, we didn't enforce that a member
reference to a typealias nested inside a generic type would supply
the generic arguments at all. To avoid breaking source compatibility,
we carved out some exceptions. Tighten up the exception to prohibit
the case where a typealias references another typealias, to fix a
crash.

While this worked in 5.1, it would crash in 5.2 and 5.3, and at
this point it's more trouble than it is worth to make it work
again, because of subtle representational issues. So let's just
ban it.

Fixes <rdar://problem/63535194>.
2020-07-08 15:52:21 -04:00
Suyash Srijan
be79d341e6 [AssociatedTypeInference] Strip 'self' parameter from function type of an enum case witness 2020-07-08 14:37:48 +01:00
Holly Borla
063d420e50 Merge pull request #32672 from hborla/property-wrapper-diagnostics
[Property Wrappers] Improve diagnostics for property wrappers initialized out-of-line
2020-07-07 19:07:55 -07:00
Mishal Shah
92ca9fc924 [Apple Silicon] Generalize tests for other macOS architectures
Most of the changes fall into a few categories:
* Replace explicit "x86_64" with %target-cpu in lit tests
* Cope with architecture differences in IR/asm/etc. macOS-specific tests
2020-07-02 16:27:46 -07:00
Holly Borla
7dffff79da [Property Wrappers] Let PropertyWrapperBackingPropertyTypeRequest
handle all errors with a property wrapper backing type.
2020-07-02 14:47:45 -07:00
Holly Borla
f555bfefc9 [Property Wrappers] Add new contextual type purposes for property wrappers
to produce better diagnostics when there's a 'wrappedValue' type mismatch.
2020-07-02 14:47:45 -07:00
Holly Borla
238637408c [Property Wrappers] Type check out-of-line initialized property wrappers
via SolutionApplicationTarget. This allows fixes to be applied and diagnosed
for better error messages in the case of failures, and removes code
duplication for generating property wrapper constraints.
2020-07-02 14:47:45 -07:00
Holly Borla
b871528179 Merge pull request #32524 from OnyekachiSamuel/fix-confusing-protocol-diagnostic
[Diagnostics] Fix Confusing Protocol Diagnostic
2020-07-02 13:01:19 -07:00
Anthony Latsis
0990ffec84 Merge pull request #32562 from AnthonyLatsis/stub-filter
Sema: Filter out conflicting requirements when printing stubs
2020-07-01 12:23:10 +03:00
Anthony Latsis
057dbbd908 Sema: Filter out conflicting requirements for protocol stubs 2020-06-28 20:47:07 +03:00
Onyekachi Ezeoke
434607d004 fix broken tests 2020-06-27 05:53:47 +01:00
Doug Gregor
2a01fc9d78 [Function builders] Run syntactic diagnostics for function bodies.
When a function body has had a function builder applied to it, make
sure that we run all of the syntactic diagnostics for expressions and
statements within the body.

Fixes rdar://problem/64493626.
2020-06-24 16:08:51 -07:00
Slava Pestov
8305d51365 Sema: Relax associated type default circularity check
We should allow an associated type's default to reference the
same associated type with a base other than 'Self'.

Note that it now becomes easier to defeat this check, but it
was never air-tight anyway -- for example, you could have a
cycle of length two if each associated type's default was the
other associated type.

This is fine, because this check is purely 'cosmetic'; nothing
goes really wrong if you have a cycle here, except that the
diagnostic shifts from the declaration of the protocol to the
conforming type.

Fixes <rdar://problem/62355224>.
2020-06-16 22:18:24 -04:00
Holly Borla
392a26323b [Property Wrappers] When generating constraints for composed property
wrappers, equate the former wrappedValue type with the current wrapper
type rather than generating value member constraints.
2020-06-16 13:58:04 -07:00
Pavel Yaskevich
82fcee7bc7 [Diagnostics] NFC: Adjust diagnostic test-cases improved by new ambiguity diagnosis 2020-06-12 13:13:27 -07:00
Pavel Yaskevich
b0070f5739 [Diagnostics] Check whether all contextual mismatches has the same type before diagnosing ambiguity
Instead of requiring sub-classes of `ContextualMismatch` to implement
`diagnoseForAmbiguity` let's implement it directly on `ContextualMismatch`
itself and check whether all of the aggregated fixes have same types on
both sides and if so, diagnose as-if it was a single fix.
2020-06-12 11:47:04 -07:00
Pavel Yaskevich
d9594c712a [TypeChecker] NFC: Adjust tests improved by new approach for ambiguity diagnosis 2020-06-12 11:47:03 -07:00
Pavel Yaskevich
ac8dfcf89b [CSGen] Replace getInterfaceType() -> mapTypeIntoContext() for VarDecl with getType
In `ConstraintGenerator::visitDeclRefExpr` instead of using
`getInterfaceType()` for unknown type and later mapping it into
context, let's use `getType()` which does that interally, that
allows to detect presence of error types in resulting type and
abort constraint generation.
2020-06-11 17:03:28 -07:00
Robert Widmann
ca728917e1 Merge pull request #32138 from AnthonyLatsis/eliminate-typeloc
Sema: Remove TypeLoc from ExplicitCastExpr (via TypeExpr)
2020-06-10 11:28:50 -07:00
Anthony Latsis
4b4634141f Sema: Remove TypeLoc from ExplicitCast 2020-06-09 15:20:25 +03:00
Doug Gregor
3e7b4ae168 [Property wrappers] Fix another opaque-result-types crasher.
Test case from Holly Borla, thank you!
2020-06-08 16:26:06 -07:00
Doug Gregor
d43c5158d9 [Property wrappers] Reject opaque result types when there is no initializer.
Fixes rdar://problem/63169705 / FB7699647.
2020-06-08 14:49:37 -07:00
Hamish Knight
9e2cdf49b3 Merge pull request #31506 from hamishknight/hello-operator 2020-05-23 09:48:21 -07:00
swift-ci
1f85c04b0c Merge pull request #31961 from CodaFi/setternalia 2020-05-21 21:25:28 -07:00
Robert Widmann
d42ac6264f Account for Deserialized VarDecls in Setter Mismatch Diagnostics
If the setter conflict occurs in a deserialized declaration, the parent
pattern binding can be NULL. Guard the fixit on the existence of the
pattern binding so

1) we don't crash
2) we don't try to emit a fixit in otherwise extremely broken code

rdar://56558082
2020-05-21 19:22:09 -07:00
Holly Borla
a97bbf9eee Merge pull request #31949 from hborla/property-wrapper-default-init
[Property Wrappers] Fix handling of properties that are default initialized via property wrapper
2020-05-21 18:01:42 -07:00
Holly Borla
1c8ad0024a [Property Wrappers] Fix ParamDecl::getDefaultValueStringRepresentation
to return a string representing default initialization when a
property is default initialized via property wrapper.
2020-05-21 14:21:50 -07:00
Suyash Srijan
d53cd535ba [Typechecker] Emit a specialised diagnostic for redeclaration errors when the declaration is synthesised (#31915)
* [Typechecker] Emit a specialized diagnostic for redeclaration errors when the declaration is synthesized

* [Test] Update existing tests

* [Typechecker] Diagnose the original wrapped property instead of the nearest non-implicit decl context

* [Test] Update existing tests

* [Typechecker] Do not diagnose redeclarations when both declarations are implicit

* [Test] Update a AutoDiff test
2020-05-21 17:37:55 +01:00
Slava Pestov
0a79beb39c Merge pull request #31871 from slavapestov/superclass-nested-type-fix
GSB: Fix maybeResolveEquivalenceClass() with member type of superclass-constrained type
2020-05-20 09:16:53 -04:00
Slava Pestov
653fa07260 GSB: Fix maybeResolveEquivalenceClass() with member type of superclass-constrained type
Name lookup might find an associated type whose protocol is not in our
conforms-to list, if we have a superclass constraint and the superclass
conforms to the associated type's protocol.

We used to return an unresolved type in this case, which would result in
the constraint getting delayed forever and dropped.

While playing wack-a-mole with regressing crashers, I had to do some
refactoring to get all the tests to pass. Unfortuanately these refactorings
don't lend themselves well to being peeled off into their own commits:

- maybeAddSameTypeRequirementForNestedType() was almost identical to
  concretizeNestedTypeFromConcreteParent(), except for superclasses
  instead of concrete same-type constraints. I merged them together.

- We used to drop same-type constraints where the subject type was an
  ErrorType, because maybeResolveEquivalenceClass() would return an
  unresolved type in this case.

  This violated some invariants around nested types of ArchetypeTypes,
  because now it was possible for a nested type of a concrete type to
  be non-concrete, if the type witness in the conformance was missing
  due to an error.

  Fix this by removing the ErrorType hack, and adjusting a couple of
  other places to handle ErrorTypes in order to avoid regressing with
  invalid code.

Fixes <rdar://problem/45216921>, <https://bugs.swift.org/browse/SR-8945>,
<https://bugs.swift.org/browse/SR-12744>.
2020-05-19 20:28:51 -04:00
Hamish Knight
cc062ee2bb Fix precedencegroup and operator decl lookup
Re-implement operator and precedencegroup decl
lookup to use `namelookup::getAllImports` and
existing decl shadowing logic. This allows us to
find operator decls through `@_exported` imports,
prefer operator decls defined in the same module
over imported decls, and fixes a couple of other
subtle issues.

Because this new implementation is technically
source breaking, as we can find multiple results
where we used to only find one result, it's placed
behind the new Frontend flag
`-enable-new-operator-lookup` (with the aim of
enabling it by default when we get a new language
mode).

However the new logic will always be used if the
result is unambiguous. This means that e.g
`@_exported` operators will be instantly available
as long as there's only one candidate. If multiple
candidates are found, we fall back to the old
logic.

Resolves SR-12132.
Resolves rdar://59198796.
2020-05-18 14:33:43 -07:00
Greg Titus
6216242c9c If the missing generic requirement includes type variables, don't emit an unhelpful note for it.
Fixes SR-12759
2020-05-18 13:40:29 -07:00
Pavel Yaskevich
d111f119d8 [ConstraintSystem] Detect and diagnose inability to infer type of closure parameter(s)
Detect situation when it's impossible to determine types for
closure parameters used in the body from the context. E.g.
when a call closure is associated with refers to a missing
member.

```swift
struct S {
}

S.foo { a, b in } // `S` doesn't have static member `foo`

let _ = { v in } // not enough context to infer type of `v`

_ = .foo { v in } // base type for `.foo` couldn't be determined
```

Resolves: [SR-12815](https://bugs.swift.org/browse/SR-12815)
Resolves: rdar://problem/63230293
2020-05-15 01:14:30 -07:00
Anthony Latsis
2643a7d8cd Sema: Apply substitutions when checking type witnesses against associatedtype superclass bounds 2020-05-15 02:16:32 +03:00