Commit Graph

77 Commits

Author SHA1 Message Date
Suyash Srijan
f7837c1694 [test] update cast diagnostics for existing tests 2019-03-21 00:22:51 +00:00
Joe Groff
7011f32d3a Merge pull request #22486 from theblixguy/fix/SR-7799
[Typechecker] Allow matching an enum case against an optional enum without '?'
2019-03-04 09:50:06 -08:00
Doug Gregor
69ef7895a8 [Constraint solver] Match argument labels for unresolved member expressions. 2019-03-01 23:11:34 -08:00
Suyash Srijan
407c38e9cd [typechecker] look through all optionals 2019-02-27 23:13:30 +00:00
Suyash Srijan
82da03733a Merge branch 'master' into fix/SR-7799 2019-02-27 22:43:08 +00:00
Pavel Yaskevich
d4b67bf3f7 [Diagnostics] Improve argument labeling diagnostics
Extend new labeling diagnostics (via fixes) to support
member references and subscripts.
2019-02-21 16:42:56 -08:00
Suyash Srijan
4e56b54b94 [typechecker] [test] cleanup 2019-02-09 17:24:12 +00:00
Suyash Srijan
7356f41881 [typechecker] allow non-optional enum case match with optional enum 2019-02-08 23:29:33 +00:00
Pavel Yaskevich
1c79380a12 [CSFix] Couple of small cleanups related to ForceOptional
* Make sure that base and unwrapped types aren't null
* Don't allocate `ForceOptional` fix if nothing has been unwrapped
  in `simplifyApplicableFnConstraint`
* Add sugar reconstitution support to `FailureDiagnostic::resolveType`
* Format diagnostics a bit better
2019-01-26 00:48:01 -08:00
Suyash Srijan
5b7fd8cc97 [test] Updates diagnostic messages for existing tests 2019-01-25 17:27:09 +00:00
Pavel Yaskevich
74a8ee177e [Diagnostics] Diagnose missing members via fixes
Try to fix constraint system in a way where member
reference is going to be defined in terms of its use,
which makes it seem like parameters match arguments
exactly. Such helps to produce solutions and diagnose
failures related to missing members precisely.

These changes would be further extended to diagnose use
of unavailable members and other structural member failures.

Resolves: rdar://problem/34583132
Resolves: rdar://problem/36989788
Resolved: rdar://problem/39586166
Resolves: rdar://problem/40537782
Resolves: rdar://problem/46211109
2019-01-09 17:29:49 -08:00
Pavel Yaskevich
dc6f86d9b7 [CSRanking] Fix solution filtering not to erase everything when set is completely ambiguous
Since constraint solver has been improved to diagnose more problems
via "fixes", sometimes applying fixes might lead to producing solutions
which are completely ambiguous when compared to each other, and/or are
incomparable, which leads to `findBestSolutions` erasing all of them
while trying to compute best "partial" solution, which is incorrect.

Resolves: rdar://problem/42678836
2018-08-06 17:25:58 -07:00
gregomni
775cca60b6 Constrain type checking of expressions in optional pattern bindings
so that they must result in an optional type.

Add constraint locator path for identifying constraints/variables that are part of the convert type passed into the system.
2018-07-27 18:05:21 -07:00
Doug Gregor
945c09b1cc [Type checker] Improve diagnostics when an optional value is not unwrapped.
When we determine that an optional value needs to be unwrapped to make
an expression type check, use notes to provide several different
Fix-It options (with descriptions) rather than always pushing users
toward '!'. Specifically, the errors + Fix-Its now looks like this:

    error: value of optional type 'X?' must be unwrapped to a value of
        type 'X'
      f(x)
        ^
    note: coalesce using '??' to provide a default when the optional
        value contains 'nil'
      f(x)
        ^
          ?? <#default value#>
    note: force-unwrap using '!' to abort execution if the optional
        value contains 'nil'
      f(x)
         ^
         !

Fixes rdar://problem/42081852.
2018-07-13 11:02:04 -07:00
Mark Lacey
ddc671c0c6 Split test case verifying we're no longer exponential type checking tuples.
Split the test case out into multiple validation scale-tests.

Add a new test for 'weak' as well.
2018-03-28 17:08:25 -07:00
Mark Lacey
9385dbb3fb Fix exponential type checking of tuple literals.
This fixes two easy cases where we would go exponential in type
checking tuple literals.

Instead of generating a conversion to a single type variable (which
results in one large constraint system), we generate a conversion ot
the same type that appears in the initializer expression (which for
tuples is a tuple type, which naturally splits the constraint system).

I experimented with trying to generalize this further, but ran into
problems getting it working, so for now this will have to do.

Fixes rdar://problem/20233198.
2018-03-26 14:46:03 -07:00
Doug Gregor
ba6f605d47 Fix some tests due to Equatable Optional/Array/Dictionary change. 2017-11-27 21:09:50 -08:00
Greg Parker
e8475cc130 Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary" 2017-11-15 14:17:22 -08:00
Doug Gregor
9f68fdae80 [Conditional conformances] Fix up test cases that changed for the better. 2017-11-14 16:23:20 -08:00
Doug Gregor
e1e0deca33 Reject unbound generic types in case patterns.
Fixes SR-6100 / rdar://problem/34898452.
2017-10-25 23:19:28 -07:00
Pavel Yaskevich
5f57183654 [QoI] Add fix-it for cases in switch with optional chaining
When type-checking switch statements with patterns let's
check if we have an optional type and try to see if the case
exists in its base type, if so we can suggest a fix-it.

Resolves: rdar://problem/32241441
2017-06-28 22:20:55 -07:00
Alex Hoppen
99acf816f4 [Diag] Correct fixit location of "?" when pattern matching optional with non-optional
Trying to pattern match an optional with a non-optional should provide
a fixit inserting a "?" after the last token and not before it.
2017-06-07 07:25:46 -07:00
Robert Widmann
4e2f36c763 Lift case redundancy checks into Sema 2017-05-01 01:32:02 -04:00
Robert Widmann
39494b2ba2 Rearrange test code for exhaustiveness 2017-04-28 02:06:39 -04:00
Joe Groff
fc16cb5dda Sema: Let .foo patterns fall back to being ExprPatterns if they don't match an enum case.
This lets you match `case .foo` when `foo` resolves to any static member, instead of only a `case`, albeit without the exhaustiveness checking and subpattern capabilities of proper cases. While we're here, adjust the type system we set up for unresolved patterns embedded in expressions so that we give better signal in the error messages too.
2017-02-28 21:51:39 -08:00
Brian King
c231b8cab3 Fix a test failure 2017-01-27 22:26:10 -05:00
Slava Pestov
1cb656314b Sema: Fix crash with unresolved 'is' pattern 2016-12-21 14:20:28 -05: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
Mark Lacey
401ca24532 Emit a warning when optionals are coerced to Any.
Emit a warning for optionals that are implicitly converted to Any, and
add fixits giving options to:
- Add '??' with a default value after
- Force-unwrap the optional with '!'
- Explicitly cast to 'as Any' to silence the warning

This covers diagnostics aspect of SE-0140.

rdar://problem/28196843
2016-09-20 22:33:45 -07:00
practicalswift
fa7fbdb8b0 [gardening] Remove redundant nil-initialization of optional variable
From the Swift documentation:

"If you define an optional variable without providing a default value,
 the variable is automatically set to nil for you."
2016-09-18 07:40:07 +02:00
Chris Lattner
807345a909 When we get an abiguity problem with a multi-statement closure return type, it is
almost always the case that the user didn't know what the rules are between
single expression and multistatement closures, and they often don't know how to
fix the problem.

Address this by doing some heroics when we detect this situation.  We now go dive
into the closure body, type check the explicit returns within it, and can usually
divine the right answer.  When we do that, generate a fixit hint that generates a
modification to the existing signature, or synthesizes the entire signature from
scratch.  This addresses:
<rdar://problem/22123191> QoI: multi-line closure with failure to infer result type should add a fixit
2016-07-30 14:36:47 -07:00
Chris Lattner
764d0fc371 improve the diagnostics for when a multi-statement closure has no inferred result type.
Previously:

error: generic parameter 'T' could not be inferred
now:
error: unable to infer closure return type in current context

There is still more to do, but this fixes:
<rdar://problem/23570873> QoI: Poor error calling map without being able to infer "U" (closure result inference)
2016-07-29 17:49:23 -07:00
Jacob Bandes-Storch
c3126e9f4f Fix ParenPattern resolution when subexpression is a NilLiteralExpr 2016-07-17 15:24:58 -07:00
Robert Widmann
a7ee8ba9cf Merge pull request #3488 from ahoppen/SR-2057-match-opt-enum
[Sema] Fix compiler crash when pattern matching optional enum
2016-07-13 08:54:56 -07:00
Alex Hoppen
a97585cbdd [Sema] Fix compiler crash when pattern matching optional enum
TypeCheckPattern was able to take the path checking if `Optional.None`
should be renamed to lowercase `Optional.none` and if this wasn't
necessary still failed but without generating a diagnostic.
Now it always provides a diagnostic when failing.

This fixes SR-2057.
2016-07-13 09:19:04 +02: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
John McCall
e75dae491e Don't diagnose failures to call symmetrically-typed binary operators
as a failure to convert the individual operand, since the operator
is likely conceptually generic in some way and the choice of any
specific overload is probably arbitrary.

Since we now fall back to a better-informed diagnostics point, take
advantage of this to generate a specialized diagnostic when trying to
compare values of function type with ===.

Fixes rdar://25666129.

This reverts commit 073f427942,
i.e. it reapplies 35ba809fd0 with a
test fix to expect an extra note in one place.
2016-05-11 16:09:28 -07:00
Ted Kremenek
073f427942 Revert "Don't diagnose failures to call symmetrically-typed binary operators"
This reverts commit 35ba809fd0.
2016-05-11 15:53:24 -07:00
John McCall
35ba809fd0 Don't diagnose failures to call symmetrically-typed binary operators
as a failure to convert the individual operand, since the operator
is likely conceptually generic in some way and the choice of any
specific overload is probably arbitrary.

Since we now fall back to a better-informed diagnostics point, take
advantage of this to generate a specialized diagnostic when trying to
compare values of function type with ===.

Fixes rdar://25666129.
2016-05-11 15:10:25 -07:00
Chris Lattner
2c81c8a114 add some parens to the testsuite, NFC. 2016-05-05 23:19:08 -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
David Farler
3f635d04c7 Reinstante var bindings in refutable patterns, except function parameters.
This reverts commits: b96e06da44,
                      8f2fbdc93a,
                      93b6962478,
                      64024118f4,
                      a759ca9141,
                      3434f9642b,
                      9f33429891,
                      47c043e8a6.

This commit leaves 'var' on function parameters as a warning to be
merged into Swift 2.2. For Swift 3, this will be an error, to be
converted in a follow-up.
2016-01-29 15:27:08 -08:00
gregomni
05ebb021ba Add a slightly less close than CC_OneArgumentMismatch closeness.
Producing single argument mismatches involving generics causes some
gross looking error messages if the generic mismatches get put into the
same closeness bucket as non-generic mismatches.

E.g. `var v71 = true + 1.0` used to produce `error: cannot convert
value of type 'Bool' to expected argument type 'Double’`, but would now
end up with `binary operator '+' cannot be applied to operands of type
'Bool' and 'Double’` `overloads for '+' exist with these partially
matching parameter lists: (Double, Double), (T, T.Stride), (T.Stride,
T)`.

Resolve this by adding CC_OneGenericArgumentNearMismatch and
CC_OneGenericArgumentMismatch, that are similar but ever so slightly
not as close as a mismatch involving non-generic functions. This gets
back the original error message in cases like the above, because there
is only one declaration of `+` which partially matches and is
non-generic, and the generic partial matches are now farther away.

But now single arg mismatches and nearness work for single-archetype
generic functions, as in the additions to the SR-69 test at the end of
deduction.swift.
2016-01-22 10:24:03 -08:00
David Farler
a6f2530780 Revert "REVERTME: Temporarily make vars in refutable patterns a warning"
This reverts commit b96e06da44, making
vars in refutable patterns an error for Swift 3.

rdar://problem/23172698
2016-01-14 20:52:24 -08:00
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Erik Eckstein
ce7b2bcf09 Revert "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit 2b2e9dc80e.

It broke some compiler crasher tests
2016-01-13 20:42:58 -08:00
gregomni
2b2e9dc80e [SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.

Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.

And then many, many changes to tests. The actual new tests for the fixits
is at the end of Generics/associated_types.swift.
2016-01-13 17:54:31 -08:00
Chris Lattner
a5a988e726 Fix rdar://22509125 QoI: Error when unable to infer generic archetype lacks greatness
Rearrange diagnoseGeneralConversionFailure to diagnose structural problems
even if we have some UnresolvedTypes floating around, then reject constraint
failures with UnresolvedTypes in them even harder.  This keeps us giving
good errors about failures where we have a structural problem (with buried
irrelevant details) while not complaining about cases that are actually
ambiguous.

The end result of this is that we produce a lot better error messages in the
case of failed archetype inference.  This also highlights the poor job we do
handling multi-stmt closureexprs...
2016-01-11 20:45:11 -08:00
Slava Pestov
f6e4355b69 Sema: Fix monthly TypeNullifier bug
This time, the issue is that TypeNullifier skips bodies of
multi-statement closures. However, ExprRewriter will type
happily pass them on to typeCheckClosureBody(). This could
trigger assertions. Fix this by skipping type checking of
multi-statement closures when diagnosing.

There seems to be a minor QoI regression in some test cases
that already looked pretty dodgy and/or had FIXMEs. However
I think its worth fixing a crash.
2015-12-11 08:58:52 -08:00
Slava Pestov
0269e0291e Sema: Fix assertion failure if EnumElementPattern is re-typechecked
We weren't actually successfully mutating ParentType,
so fix that, and also ensure we set ParentType together
with the rest of the state.

Discovered while writing resilient enum tests.
2015-12-11 08:58:51 -08:00