Commit Graph

31 Commits

Author SHA1 Message Date
Anthony Latsis
bc4a3465a9 Gardening: Migrate test suite to GH issues: Generics 2022-08-30 01:49:59 +03:00
Slava Pestov
dac8d666ee Stop passing -requirement-machine-{abstract,inferred,protocol}-signatures flags in tests
These flags are now no-ops.
2022-05-10 12:56:17 -04:00
Slava Pestov
01fea564fb RequirementMachine: Skip emitting diagnostics containing ErrorTypes 2022-04-01 01:04:54 -04:00
Robert Widmann
363b66a7ad Fully Qualify the Parent Type When Diagnosing Missing Member Types
Use the FullyQualified<Type> abstraction from the prior commit plus DescriptiveDeclKind to give a bit more information when issuing a missing member type diagnostic during type resolution.
2020-11-09 17:10:18 -08:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Anthony Latsis
d688710fb3 [Diag] Move invalid where clause on top-level decl diagnostic to Sema 2020-03-15 13:38:49 +03:00
fischertony
eb539e62f8 Parse: Diagnose where clauses early on non-generic top-level declarations 2020-03-04 15:04:28 +03:00
Sam Lazarus
de7851b0e9 Test: Update tests to reflect change to generic mismatch note locations 2019-06-14 12:35:32 -04:00
Sam Lazarus
dc5ccd1349 Test: Add tests for the new generic arguments mismatch diagnostic 2019-06-14 12:35:31 -04:00
Sam Lazarus
7719b0f461 Sema: Add a more descriptive diagnostic for generic argument mismatches 2019-06-14 12:35:31 -04:00
Pavel Yaskevich
c30845fa74 [ConstraintSystem] Detect and diagnose missing generic arguments
Introduce a fix to detect and diagnose situations when omitted
generic arguments couldn't be deduced by the solver based on
the enclosing context.

Example:

```swift
struct S<T> {
}

_ = S() // There is not enough context to deduce `T`
```

Resolves: rdar://problem/51203824
2019-05-29 16:39:41 -07:00
Slava Pestov
043faefb21 Sema: Fix a failure to emit a diagnostic when generic requirements aren't satisfied
In the stuctural type resolution stage we don't have enough information
to check conformance and same-type requirements involving type
parameters, so we would just ignore such requirements, assuming they
will be checked later in the interface stage.

However, there was a case where we would return an error type without
emitting a diagnostic, assuming that at least one other requirement
fails. If a TypeLoc has an error type we don't resolve it again in
the interface type stage. So we would end up with an error type and
no diagnostic.

Fix this by not checking generic arguments in the structural stage at
all; we will do the complete check in interface stage, where we know
how to check everything and emit all the right diagnostics.

Fixes <rdar://problem/45271500>.
2018-10-26 16:38:10 -04:00
Doug Gregor
fa0c986c25 [Type checker] Make sure we fully validate ‘where’ clauses in protocols.
Fixes SR-5579 and an existing crash.
2017-09-29 11:23:45 -07:00
Slava Pestov
eb46696baa AST: Fix bogus diagnostic with bad conformance requirements in generic signature
Fixes <rdar://problem/33604221>.
2017-07-31 14:19:19 -07:00
Pavel Yaskevich
3a77295835 [QoI] Use information known about call parameters via failed constraint
This makes it a lot easier to diagnose contextual mismatch related
to arguments used by the call without relying on the type of the
function expression which is not always available.
2017-06-21 11:27:12 -07:00
Pavel Yaskevich
c46e3e83e8 [QoI] Improve diagnostics for single argument calls with trailing closures
Calls involving single trailing closure arguments require special
handling because we don't have as much contextual information
about function/argument types as in with regular calls, which means
that diagnosing such situations only by `visitApplyExpr`
yields subpar results.

Resolves: SR-4836.
2017-06-21 11:26:38 -07:00
Slava Pestov
cde493de0d Sema: Support member types in preCheckExpression()
This folds member access on types to a TypeExpr if the member
resolves to a nested type.

This allows [Foo.Bar]() to become an ApplyExpr of a TypeExpr,
rather than an ApplyExpr of an array literal; previously,
only [Foo]() worked.

Two cases that are still unsupported:

1) If G is a generic type and T is a generic typealias, then
   G.T<X> cannot be folded to a TypeExpr, because we cannot
   represent a generic typealias with an unbound generic
   parent type. Such lookups remain member lookups, where
   Sema first opens the base type to produce a bound generic
   type G<$T0>, and then resolves the generic typealias
   member on that.

2) If T is a generic parameter and X is an associated type,
   T.X is not folded down to a TypeExpr either.

Fixes <rdar://problem/16849958>.
2017-05-21 18:12:12 -07:00
Slava Pestov
7f3c97bf8b AST: More consistent spelling of 'type alias' in diagnostics
Some messages said 'typealias' and others said 'type alias'.
Change everything to use 'type alias' consistently (except
when it's talking about the keyword itself).
2017-04-23 00:02:30 -07:00
Doug Gregor
c522bb5239 [GSB] Separate out "unresolved" and "direct" type requirement handling.
As we've done with layout requirements, introduce a new entry point
(addTypeRequirement) that handles unresolved type requirements of the
form `T: U`, resolves the types, and then can

1. Diagnose any immediate problems with the types,
2. Delay the type requirement if one of the types cannot be resolved,
or
3. Break it into one or more "direct" requirements.

This allows us to clean up and centralize a bunch of checking that was
scattered/duplicated across the GSB and type checker.
2017-04-07 16:53:11 -07:00
Doug Gregor
44c2f849d6 [Type checker] Continue validating requirements after an error.
We want to validate both type in same-type or conformance constraints,
even when the first type is ill-formed, so we don't leave null types
around for later phases to crash on.

Fixes rdar://problem/31093854.
2017-04-05 14:05:59 -07:00
Doug Gregor
ab7cd7fbe4 Enable associated type where clauses in all language modes
We're ready to start experimenting with and rolling out this feature
in earnest.
2017-04-04 10:58:01 -07:00
Huon Wilson
54f247693c [AST]/[Parse] parse where clauses on protocol declarations. 2017-03-09 16:08:16 -08:00
Huon Wilson
8423018057 [Parse] Parse trailing where clauses on associated types. 2017-02-24 19:21:32 -08:00
Slava Pestov
b9a4f4af03 ArchetypeBuilder: Drop requirements containing concrete types with unresolved associated types
When building a generic signature, we would drop requirements
where the LHS or RHS was a DependentMemberType with an unresolved
associated type, however we didn't perform the same check for
DependentMemberTypes that are nested inside structural types.
2016-12-19 18:49:57 -08:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Slava Pestov
a760186505 AST: Remove -enable-experimental-nested-generic-types flag 2016-11-18 00:39:15 -08:00
Joe
3938d5682a [SE-0095] [Runtime], [Demangler], & AST printer updated to new composition syntax
- All parts of the compiler now use ‘P1 & P2’ syntax
- The demangler and AST printer wrap the composition in parens if it is
in a metatype lookup
- IRGen mangles compositions differently
    - “protocol<>” is now “swift.Any”
    - “protocol<_TP1P,_TP1Q>” is now “_TP1P&_TP1Q”
- Tests cases are updated and added to test the new syntax and mangling
2016-07-19 12:01:37 -07:00
Joe
a6dad0091b [SE-0095] Initial parsing implementation for '&' composition syntax
This commit defines the ‘Any’ keyword, implements parsing for composing
types with an infix ‘&’, and provides a fixit to convert ‘protocol<>’

- Updated tests & stdlib for new composition syntax
- Provide errors when compositions used in inheritance.
Any is treated as a contextual keyword. The name ‘Any’
is used emit the empty composition type. We have to
stop user declaring top level types spelled ‘Any’ too.
2016-07-19 12:01:02 -07:00
Slava Pestov
612991e903 Add two test cases with an unclear diagnostics 2016-06-23 00:01:39 -07:00
Slava Pestov
3a043a25e1 Sema: Hacky fix for a crash in CSDiag
It looks like the mapTypeIntoContext() call is using the wrong
'dc', because in fact we have no way of knowing what the original
'dc' was which produced the type parameters in question.

Really the problem is we're picking apart SubstitutedType here,
which is almost always the wrong thing to do. I don't think
SubstitutedType should exist at all.

To avoid the crash, just bail-out if 'dc' is not generic.

I'm intentionally avoiding a principled fix here to hasten the
apocalypse when all of CSDiag.cpp will collapse under its own
weight and get rewritten in a sane way.
2016-06-21 16:25:29 -07:00
Slava Pestov
5b4ee41772 Parser: Diagnose if free-standing 'where' clause is attached to a non-generic declaration
Previously we would produce an empty GenericParamList, crashing Sema.
2016-06-18 17:15:25 -07:00