Commit Graph

259 Commits

Author SHA1 Message Date
Vinicius Vendramini
39d3963131 Fix broken tests
- Many tests got broken because of two things:
  - AST dump now outputs to stdout, but many tests expected stderr. This was a straightforward fix.
  - Many tests call swift with specific parameters; specifically, many call `swift frontend` directly. This makes them go through the compiler in unexpected ways, and specifically it makes them not have primary files, which breaks the new AST dump implementation. This commit adds the old implementation as a fallback for those cases, except it dumps to `stdout` to maintain some consistence.

Finally, the `/test/Driver/filelists.swift` failed for unknown reasons. It seems its output now had some lines out of order, and fixing the order made the test pass. However, as the reasons why it failed are unknown, this fix might not have been a good idea. Corrections are welcome.
2018-11-14 13:38:01 -02:00
Greg Titus
d20fdf5f82 Merge pull request #19920 from gregomni/8757
[Sema][QoI] Call out missing conformances in protocol witness candidates.
2018-10-22 16:39:51 -07:00
gregomni
939de4fb4a Extend candidate missing conformance checking to other types of requirements so that we check superclass and same type requirements in the same way. 2018-10-19 10:02:30 -07:00
Greg Titus
4f8e3f3597 Merge pull request #19879 from gregomni/8757
[Sema] Omit protocol match diagnosis for constructors with differing names.
2018-10-16 09:36:16 -07:00
Greg Titus
7d0bdb112e Omit protocol match diagnosis for constructors with differing names. 2018-10-14 17:08:50 -07:00
gregomni
42a24ebb71 Use hasDynamicSelfType and add another test where the result type is complex and includes the non-dynamic self. 2018-10-11 13:31:56 -07:00
gregomni
679ac44f1f Add check for dynamic self in the witnessing type, and test. This would also fail to infer previously. 2018-10-09 07:04:07 -07:00
gregomni
eae1015072 Allow associated type inference for requirement returning dynamic Self when witness returns self type and isn't a class or is a final class. (Same as meeting the requirement.) 2018-10-07 09:24:54 -07:00
Slava Pestov
c3f02b14d3 Add test case for https://bugs.swift.org/browse/SR-1571 2018-10-05 16:56:46 -04:00
Pavel Yaskevich
63b802ca88 [AST/Printing] Don't omit empty labels in special names
This makes diagnostics more verbose and accurate, because
it's possible to distinguish how many parameters there are
based on the message itself.

Also there are multiple diagnostic messages in a format of
`<descriptive-kind> <decl-name> ...` that get printed as
e.g. `subscript 'subscript'` if empty labels are omitted.
2018-09-24 18:36:53 -07:00
Davide Italiano
ef46ec08fc [AST] Update tests now that we preserve sugar. 2018-09-18 09:23:02 -07:00
Mark Lacey
78d83e5703 Use %target-typecheck-verify-swift where possible. 2018-07-26 23:13:43 -07:00
Doug Gregor
6a8d3211aa [Type checker] Move ad-hoc isObjC/isDynamic checking to finalization.
Whenever we visit a declaration via the DeclChecker, add it to the
list of declarations to finalize. This makes sure that we can centralize
the notion of “finalize for SILGen” and that it will be called for
everything in the source file being processed.
2018-07-25 20:55:13 -07:00
Slava Pestov
31ab93b82c Remove Swift 3-specific tests 2018-07-02 21:14:22 -07:00
Slava Pestov
3701f745c4 Migrate various Sema tests to Swift 4 2018-06-25 01:02:20 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Mark Rowe
62eb12b652 Include source ranges for decls in the AST dump. 2018-05-17 10:50:19 -07:00
Ben Langmuir
f20586b3d8 Revert "Include source ranges for statements, declarations, and parameter lists in the AST dump" 2018-05-17 09:53:05 -07:00
Jordan Rose
cb6c8f0a8e Merge pull request #16473 from bdash/ast-dump-source-ranges
Include source ranges for statements, declarations, and parameter lists in the AST dump
2018-05-17 09:16:35 -07:00
Jordan Rose
6bd7e5e5b4 Make sure protocol witness errors don't leave the conformance context
That is, if there's a problem with a witness, and the witness comes
from a different extension from the conformance (or the original type,
when the conformance is on an extension), put the main diagnostic on
the conformance, with a note on the witness. This involves some
shuffling and rephrasing of existing diagnostics too.

There's a few reasons for this change:

- More context. It may not be obvious why a declaration in file
  A.swift needs to be marked 'public' if you can't see the conformance
  in B.swift.

- Better locations for imported declarations. If you're checking a
  conformance in a source file but the witness came from an imported
  module, it's better to put the diagnostic on the part you have
  control over. (This is especially true in Xcode, which can't display
  diagnostics on imported declarations in the source editor.)

- Plays better with batch mode. Without this change, you can have
  diagnostics being reported in file A.swift that are tied to a
  conformance declared in file B.swift. Of course the contents of
  A.swift also affect the diagnostic, but compiling A.swift on its
  own wouldn't produce the diagnostic, and so putting it there is
  problematic.

The change does in some cases make for a worse user experience,
though; if you just want to apply the changes and move on, the main
diagnostic isn't in the "right place". It's the note that has the info
and possible fix-it. It's also a slightly more complicated
implementation.
2018-05-10 19:31:12 -07:00
Jordan Rose
545b12fa9f Convert backticks to single-quotes in Sema diagnostics
Let's be consistent!
2018-05-09 21:59:39 -07:00
Mark Rowe
28af6959b8 Include source ranges for decls in the AST dump. 2018-05-09 11:15:35 -07:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Huon Wilson
2e5799e26b [Sema] Diagnose redundant conditional conformances more specifically.
We don't allow things like

    extension Type: P where Param: P {}
    extension Type: P where Param: Q {}

or

    extension Type: P where Param == Int {}
    extension Type: P where Param == Float {}

or

    extension Type: P where Param: P {}
    extension Type: P where Param == SomethingThatIsntP {}

and the default error message "redundant conformance" message doesn't convey
this very well.

Fixes rdar://problem/36262409.
2018-04-27 11:50:17 +10:00
Slava Pestov
510f842488 AST: Workaround for same-type constraints getting dropped from requirement environment
The fix for <https://bugs.swift.org/browse/SR-617> introduced
a new kind of requirement environment where 'Self' remains a
generic parameter, but receives a class constraint, instead of
becoming fully concrete.

As before, we would form the synthetic signature by taking
the generic signature of the requirement, and substituting it
the new 'Self' type.

However, whereas previously the 'Self' type was always concrete
and any DependentMemberTypes in the requirement's signature
would become concrete type references, with a class-constrained
'Self' the DependentMemberTypes remain.

Apparently, the GSB cannot handle DependentMemberTypes where
the base is class-constrained.

Work around this by ensuring that we add a conformance constraint
for the 'Self' parameter to the protocol in question, which
allows the DependentMemberTypes to be correctly resolves once
the conformance is made concrete by a superclass constraint.

The FIXME comment being removed here references crashes which
no longer seem to reproduce, so I'm assuming some underlying
GSB issues got fixed and the FIXME is clearly no longer necessary.

However, I still consider this fix somewhat unsatisfying, because
it is not clear if there's some deeper flaw in how the GSB
models superclass constraints. It might resurface again in the
future.

Fixes <rdar://problem/39419121>, <https://bugs.swift.org/browse/SR-7428>.
2018-04-16 22:22:52 -07:00
Slava Pestov
08e4e7c990 Add test for https://bugs.swift.org/browse/SR-7422 2018-04-13 13:33:23 -07:00
Devin Coughlin
da6d078ff9 [Tests] Remove dependence on specific deployment target versions (#15819)
Generalize several tests so they are not locked to specific deployment target
versions.
2018-04-09 14:10:32 -07:00
Slava Pestov
a5579d1cff AST: Plug a hole in access control checking
A protocol extension of a private protocol can define internal
or public members. We should not be able to find these members
from another file or module if an internal or public type
conforms to the protocol.

Fixes <rdar://problem/21380336>.
2018-04-05 23:24:48 -07:00
Doug Gregor
e82e7ee908 [Type checker] Use BoundNameAliasType for all typealiases.
Rather than relying on the NameAliasType we get by default for references
to non-generic typealiases, use BoundNameAliasType consistently to handle
references to typealiases that are formed by the type checker.
2018-03-25 21:35:16 -07:00
Doug Gregor
790625ab5b Allow a witness's noescape parameter to match a requirement's escaping parameter
Extend protocol conformance checking to allow a requirement with an
escaping parameter (of function type) to be satisfied by a witness
with a corresponding non-escaping parameter. This limited form of
covariance was already supported by SILGen and is needed to address
the source-compatibility "regression" introduced by inferring escaping
function types for associated type witnesses. It's also obviously a
good idea :)

Fixes rdar://problem/35297911.
2018-03-20 13:02:49 -07:00
Doug Gregor
f24c2eb94c [Associated type inference] Infer escaping function types, not noescape ones.
When inferring an associated type witness by matching a function signature,
adjust non-escaping function types to escaping function types, because only
escaping function types could be written as explicit witnesses and
non-escaping function types are not permitted outside of function
parameters.

Addresses the first part of rdar://problem/35297911, eliminating the
type-soundness issue.
2018-03-20 13:02:49 -07:00
Michael Gottesman
c1bc576cdc Revert "[Associated type inference] Infer escaping function types, not noescape ones."
This reverts commit 60e8de7b65.
2018-03-19 18:54:24 -07:00
Michael Gottesman
2c0d406749 Revert "Allow a witness's noescape parameter to match a requirement's escaping parameter"
This reverts commit 44e230b91a.
2018-03-19 18:54:24 -07:00
Doug Gregor
44e230b91a Allow a witness's noescape parameter to match a requirement's escaping parameter
Extend protocol conformance checking to allow a requirement with an
escaping parameter (of function type) to be satisfied by a witness
with a corresponding non-escaping parameter. This limited form of
covariance was already supported by SILGen and is needed to address
the source-compatibility "regression" introduced by inferring escaping
function types for associated type witnesses. It's also obviously a
good idea :)

Fixes rdar://problem/35297911.
2018-03-19 15:29:32 -07:00
Doug Gregor
60e8de7b65 [Associated type inference] Infer escaping function types, not noescape ones.
When inferring an associated type witness by matching a function signature,
adjust non-escaping function types to escaping function types, because only
escaping function types could be written as explicit witnesses and
non-escaping function types are not permitted outside of function
parameters.

Addresses the first part of rdar://problem/35297911, eliminating the
type-soundness issue.
2018-03-19 14:38:40 -07:00
Saleem Abdulrasool
b67d5f0cf7 test: convert rm -rf && mkdir -p into %empty-directory
This converts the instances of the pattern for which we have a proper
substitution in lit.  This will make it easier to replace it
appropriately with Windows equivalents.
2018-03-06 14:30:54 -08:00
Erik Eckstein
2a7c9587ad NSArchive support: don't eagerly create class metadata for nested classes.
This is not required anymore to be able to unarchive such classes (before the first object of the class is instantiated).

rdar://problem/37568342
2018-02-16 15:36:52 -08:00
Doug Gregor
9b2c462709 [Conformance checking] Factor out associated type inference.
Move associated type inference into its own class, to make this
code easier to understand/maintain/improve. Minor diagnostics changes
because we're properly passing uninference associated type declarations
to the "group" checker.
2017-12-09 23:05:24 -08:00
Slava Pestov
4e8bdcd716 Sema: Type aliases with an unbound generic type cannot witness associated type requirements
We allow definitions like this:

struct G<T> {}
typealias A = G

As a shorthand for

typealias A<T> = G<T>

A typealias like this cannot satisfy an associated type requirement
for the same reason that a generic typealias cannot satisfy an
associated type requirement, which was already handled.

Previously this would crash in the type checker or in IRGen.

This fixes a weird regression in a fixed compiler crasher from the
next patch.
2017-11-04 23:40:23 -07:00
Slava Pestov
398f76d12b Sema: Check AnyObject constraint on associated type witnesses
Fixes <https://bugs.swift.org/browse/SR-6109>, <rdar://problem/34911213>.
2017-10-31 19:35:31 -07:00
Doug Gregor
587cd4e463 Suppress inference of @_staticInitializeObjCMetadata for "newer" classes.
If a class was introduced in an OS newer than the deployment target,
suppress the inference of @_staticInitializeObjCMetadata, because
the resulting eager initialization will crash when run on older OS's.
This is a stop-gap solution; we want the eager initialization code to
check availability before registering the class, but that requires more
effort.

Fixes the main part of SR-6203 / rdar://problem/35161939.
2017-10-25 17:05:11 -07:00
Slava Pestov
7cbd0c0b37 Sema: Lift restriction on classes conforming to protocols with default implementations returning 'Self'
Now that we pass in the correct type metadata for 'Self', it is
sound for a class to conform to a protocol with a default implementation
for a method returning 'Self'.

Fixes <rdar://problem/23671426>.
2017-10-09 19:53:51 -07:00
Jordan Rose
192b523a8e Revert "Fix issue with 'Self' metadata when class conforms to protocol with default implementations" (#12344)
It broke the 32-bit iOS simulator, and possibly the 64-bit simulator as well. Reverts 5618553.
2017-10-09 10:02:48 -07:00
Slava Pestov
80ada27707 Sema: Lift restriction on classes conforming to protocols with default implementations returning 'Self'
Now that we pass in the correct type metadata for 'Self', it is
sound for a class to conform to a protocol with a default implementation
for a method returning 'Self'.

Fixes <rdar://problem/23671426>.
2017-10-09 00:53:03 -07:00
Alex Hoppen
2dd670ba8b Add test cases for special subscript name 2017-07-11 19:04:13 +02:00
Doug Gregor
a570a5a15e [Type checker] Check type equality even for argument tuples in Swift 4.
Replace a where Type-pointer-equality check with what it intended,
i.e., match up ParenTypes at the top level and perform a deeper
equality comparison of the underlying types.

Fixes SR-5166 / rdar://problem/32666189.
2017-06-20 23:49:47 -07:00
Xi Ge
568c861adc [FixCode] Protocol stubs shouldn't print any @ attributes.
This also addresses @jrose-apple's code review comments.
2017-06-16 16:04:57 -07:00
Xi Ge
088e4cd56b test: use platform-independent @available attribute and re-enable fixit_stub_editor.swift (#10322) 2017-06-16 14:02:54 -07:00
Jordan Rose
65ccd84943 [test] Disable fixit_stub_editor.swift entirely until fixed. (#10312)
Tracked by rdar://problem/32804941.
2017-06-16 09:33:46 -07:00
Mishal Shah
946cc75fbb Revert "Build fix: Update fix-it stub editor test"
This reverts commit 9a17226d26.
2017-06-15 22:17:53 -07:00