Commit Graph

46 Commits

Author SHA1 Message Date
Suyash Srijan
a5241edae9 [MiscDiagnostics] Suppress KVO warning when the property has an explicit setter (#30098) 2020-02-27 22:41:50 +00:00
Pavel Yaskevich
87beea3c40 [ConstraintSystem] Use binding as a source of type variable assignment
Since `binding` has all of the required information now it's possible
to use its `locator` as a source of type variable assignment
(`Bind` constraint) in `TypeVariableBinding::attempt` which helps
to improve diagnostics.
2019-12-12 12:42:30 -08:00
Suyash Srijan
fab6ce9587 [MiscDiagnostics] Diagnose passing a non-@objc dynamic KeyPath property to KVO observe method 2019-11-08 18:52:43 +00:00
Rintaro Ishizaki
572cfe26a9 Revert "[SyntaxParse] Parse ObjC keypath expression syntax"
This reverts commit 1036d2a2bf.
2019-10-14 12:11:40 -07:00
Rintaro Ishizaki
1036d2a2bf [SyntaxParse] Parse ObjC keypath expression syntax 2019-10-11 11:55:22 -07:00
Sam Lazarus
ede8127adf Test: Add and update tests for allowing var and let as argument labels 2019-04-26 04:08:27 -04:00
Suyash Srijan
072e84acd6 [CSSimplify] Reject key path if root type is AnyObject (#23820)
Detect situations where `AnyObject` is attempted to be used as a root type of the key path
early and diagnose via new diagnostics framework.
2019-04-14 12:18:35 -07:00
Parker Schuh
d0779bd771 Convert ArrayExpr to not use callWitness() or generate a SemanticExpr. 2019-03-27 23:21:08 -04:00
Pavel Yaskevich
688042becf [Diagnostics] Add inaccessible member diagnostic 2019-03-18 13:48:08 -07:00
Saleem Abdulrasool
b1deb97344 test: explicitly indicate interpreter for utils
This fixes the last couple of instances of the interpreter not being
passed to the python the scripts which makes them fail on OSes where
shebangs are not honoured (i.e. Windows)
2019-02-05 10:25:36 -08:00
Suyash Srijan
fa82965a7d [CSApply] Fix an issue with the @objc selector fix-it incorrectly being applied (#20949)
Special-case the diagnostic for members of non-@objc protocols that are referenced in #selector expressions.
2018-12-11 13:19:46 -05:00
Mark Lacey
a5d627844a Merge pull request #20618 from rudkx/favor-equality
[ConstraintSystem] When we have multiple conversions/fixes, make equa…
2018-11-16 06:27:42 -08:00
Mark Lacey
33b6e43efa [ConstraintSystem] When we have multiple conversions/fixes, make equality favored.
This allows us to skip attempting actual conversions.

This speeds up one of our slow test cases, and perturbs the output of
another test. In the latter case, we stop emitting conversions as part
of the non-semantic piece of the array_expr. The fact that we're not
putting conversions in on that path is something I've seen before in
other instances. I'll open a bug if I cannot find one for it, although
I believe it's entirely cosmetic in this case since we don't rely on
the conversion being there.
2018-11-15 17:38:22 -08:00
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
Doug Gregor
f39fe1a755 [Tests] Put NSObject Equatable/Hashable back in the ObjectiveC module.
Technically, these operations belong in the ObjectiveC module, where NSObject
is defined. Keep them there. However, we need to build the mock ObjectiveC
overlay with `-disable-objc-attr-requires-foundation-module` now.
2018-08-01 09:25:28 -07:00
Jordan Rose
6290d9be60 Introduce DescriptiveDeclKind::Property (#18183)
...and collapse StaticVar/ClassVar and StaticLet/ClassLet into
StaticProperty/ClassProperty.

"var" and "let" aren't great nouns to use in diagnostics to begin with,
especially alongside semantic terms like "instance method". Focus on
the type vs. non-type aspect instead with "property", which better
matches how people talk about member vars (and lets) anyway.
2018-07-30 09:23:59 -07:00
Doug Gregor
9b888533d4 [Serialization] Serialize Objective-C method names for accessors.
Due to some short-circuiting in the serialization logic, we never
added @objc getters/setters to a module’s Objective-C method table.
2018-07-25 16:48:50 -07:00
Mark Lacey
16a0808f2c Revert "[TypeChecker] Fix crash with Objective C keypaths." 2018-06-26 17:18:12 -07:00
Mark Lacey
846f159a5c Also check for error_type in ObjC keypath validation.
And add a test that exercises this exit path (although it won't crash
a compiler without my fixes because we do end up with ErrorType in
that case, not a nullptr).
2018-06-25 23:15:10 -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
Mark Rowe
28af6959b8 Include source ranges for decls in the AST dump. 2018-05-09 11:15:35 -07:00
Doug Gregor
3b896e0a41 [Collection upcast optimization] Address review feedback.
All NFC cleanups.
2018-04-18 09:26:52 -07:00
Doug Gregor
eaba3b3192 [Type checker] Factor out the collection upcast peephole code.
While here, cope with extra parentheses as well. They shouldn't
inhibit this optimization.
2018-04-17 15:21:48 -07:00
Doug Gregor
10c53f4cd8 [Type checker] Extend the upcast-of-literal peephole to dictionary literals.
When the operand of a collection upcast is a dictionary literal,
upcast the elements of the collection instead. This avoids going
through the dynamic-casting machinery.
2018-04-17 14:50:46 -07:00
Doug Gregor
4acbf586eb [AST] Optimize collection upcasts of array literals.
When we form a collection upcast of an array literal, upcast the
individual elements directly so we avoid a call through the
runtime. This both improves code generation and sidesteps a regression
involving the inability to dynamically cast function types.

Fixes SR-7362 / rdar://problem/39218656.
2018-04-17 14:08:14 -07:00
Rintaro Ishizaki
5baf106c20 [test][gardening] move test files to appropriate directory
`#selector` and `#keyPath` are parsed in parseExprPrimary
2018-03-15 17:45:32 +09:00
David Rönnqvist
57731ebc09 [QoI] [Parse] Improve error message when parsing floating point exponent
Update error messages to mention the invalid character.
Improve the diagnostic of floating point exponents.

Add tests for error messages when parsing floating point exponents.
Update existing tests for new error messages.
2017-07-08 13:32:34 +02:00
David Rönnqvist
a615d9ede3 [QoI] Improve error message when parsing integer literal
Rephrased error message to indicate which character is unexpected.
Provide error message variations when parsing binary, octal, decimal (default), and hexadecimal integer literals.
Look for unexpected digits in binary and octal integer literals.
Look for unexpected letters in hex integer literals.

Resolves: SR-5236 rdar://problem/32858684
2017-07-06 19:59:09 +02:00
Andrew Bennett
ca31338e49 Simplifying implementation of ExpressibleByStringLiteral (#7125)
* Simplify conforming to ExpressibleByStringLiteral with default implementations

* attributes on default implementations

* ExpressibleByUnicodeScalarLiteral validation test

* more generic default implementations

* clean up test

* remove unneeded implementations

* remove test verification

* indent

* revert @effects and affected methods

* fix test generics with _ protocols

* Add semantic tests

* clean up tests

* Fix redundant conformance requirements
2017-04-21 20:45:28 -07:00
Slava Pestov
fbdecebf77 AST: Restore unqualified lookup quirk for Swift 3 mode
In Swift 3, unqualified lookup would skip static methods
when performing a lookup from instance context.

In Swift 4 mode, if a module method is shadowed by a static
method, you will need to qualify the module method with the
module name.

It would have been nice to isolate the quirk in Sema and
not AST, but unfortunately UnqualifiedLookup only proceeds
to lookup in the module if scope-based lookup failed to find
anything, and I don't want to change that since it risks
introducing performance regressions.

Fixes <rdar://problem/29961715>.
2017-01-12 22:43:23 -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
Rintaro Ishizaki
47e07bc611 [Parse] Create DiagnosticTransaction along with BacktrackingScope
This prevents duplicated diagnostics.
2016-10-27 11:58:08 +09:00
Slava Pestov
22aa032285 Sema: Clean up SE-0036 diagnostic a bit
Suggest a fix-it for unqualified references to all static members
from instance context, not just enum elements.

Also, fix a small problem with the fix-it for replacing protocol
names with 'Self' inside extension bodies -- we didn't handle nested
functions properly.
2016-08-05 14:27:16 -07:00
Slava Pestov
3ebd53d03c AST: Name lookup shouldn't filter out static/instance methods from instance/static context
We do this in a more general way higher up in the constraint
solver. Filtering out methods in name lookup only hurts
diagnostics.

In fact I don't think this behavior was intentional at all,
since the code in question was originally written in 2013
before a lot of the more recent member lookup and diagnostic
code was added.

This does break source compatibility though, but in a minor
way. See the change to the CoreGraphics overlay. Again,
though, I think this was an accident and not intentional.
2016-08-05 14:27:16 -07:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Doug Gregor
ab31f08848 [Parser] Disambiguate between object literals and collection literals.
Now that we have expressions that start with #, the [# introducer for
object literals is no longer guaranteed to indicate an object
literal. For example:

    [#line, #column]

is an array literal and

    [#line : #column]

is a dictionary literal. Use additional lookahead in the parser to
disambiguate these cases from object literals. Fixes
rdar://problem/24533081.
2016-02-05 17:14:20 -08:00
Doug Gregor
74c0b113b2 Add test for parsing of unqualified-decl-name with missing '_' in the middle. 2016-01-21 15:06:09 -08:00
Doug Gregor
c9c1d1390c [SE-0021] Allow naming of specific initializers via "self.init(foo:bar:)". 2016-01-20 17:09:02 -08:00
Doug Gregor
ecfde0e71c Start parsing names with argument labels.
Basic implementatation of SE-0021, naming functions with argument
labels. Handle parsing of compound function names in various
unqualified-identifier productions, updating the AST representation of
various expressions from Identifiers to DeclNames. The result doesn't
capture all of the source locations we want; more on that later.

As part of this, remove the parsing code for the "selector-style"
method names, since we now have a replacement. The feature was never
publicized and doesn't make sense in Swift, so zap it outright.
2016-01-20 17:09:01 -08:00
Chris Lattner
4366da9250 more testcase updates for upcoming diagnostics change.
Swift SVN r28409
2015-05-11 06:05:00 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Doug Gregor
d93eaed9f7 Switch BooleanLiteralConvertible over to an initializer requirement.
Conforming to BooleanLiteralConvertible now requires

  init(booleanLiteral: Bool)

rather than

  static func convertFromBooleanLiteral(value: Bool) -> Self

This posed a problem for NSNumber's conformance to
BooleanLiteralConvertible. A class needs a required initializer to
satisfy an initializer requirement, but one cannot add a required
initializer via an extension. To that end, we hack the Clang importer
to import NSNumber's initWithBool with the name

  init(booleanLiteral:)

and add back the expected init(bool:) initializer in the
overlay. These tricks make NSNumber even harder to subclass, but we
don't really care: it's nearly impossible to do well anyway, and is
generally a Bad Idea.

Part of rdar://problem/18154091.

Swift SVN r21961
2014-09-15 23:59:30 +00:00
Doug Gregor
2f3f6acf21 Make "true" and "false" Boolean literal constants for the BooleanLiteralConvertible protocol.
Introduce the new BooleanLiteralConvertible protocol for Boolean
literals. Take "true" and "false" as real keywords (which is most of the
reason for the testsuite churn). Make Bool BooleanLiteralConvertible
and the default Boolean literal type, and ObjCBool
BooleanLiteralConvertible. Fixes <rdar://problem/17405310> and the
recent regression that made ObjCBool not work with true/false.


Swift SVN r19728
2014-07-09 16:57:35 +00:00