Commit Graph

27 Commits

Author SHA1 Message Date
Karl Wagner
ab4f80ed95 [SE-0404] Allow protocols to be nested in non-generic contexts 2023-10-06 21:04:03 +02:00
Anthony Latsis
6704aabb20 Gardening: Migrate test suite to GH issues: decl/inherit 2022-08-26 03:26:32 +03:00
John McCall
a30d91e3cb Implement vararg expansion well enough to support argument forwarding.
I needed this for materializeForSet remission, but it makes inherited
variadic initializers work, too.

I tried to make this a reasonable starting point for a real language
feature.  Here's what's still missing:

- syntax
- semantic restrictions to ensure that the expression isn't written in
  invalid places or arbitrarily converted
- SILGen support for expansions that aren't the only variadic argument

rdar://16331406
2018-08-22 06:46:08 -04:00
Slava Pestov
64593330a5 Add regression test for https://bugs.swift.org/browse/SR-5056
This looks like a subtle issue. It was broken in 4.1 and got fixed in
4.2, perhaps by the decl checker cleanups or some other change.

I don't see many occurrences of 'required convenience' in the
non-executable tests, period, so it's good to have a bit more
coverage for this corner of the language.
2018-08-09 17:20:03 -07:00
Pavel Yaskevich
84cd99a3eb [Diagnostics] Enable extraneous/incorrect label diagnostics via solver fixes
This builds on initial commit which added `RelabelArguments` fix
to the solver that only supported `missingLabels` at that moment,
but now it supports all three posibilities - missing/extraneous and
incorrect labels.
2018-07-25 14:34:26 -07:00
Slava Pestov
0e91735822 Sema: Implement inheritance of initializers with generic parameters
Fixes <https://bugs.swift.org/browse/SR-3848>.
2018-06-20 22:56:44 -07:00
Doug Gregor
b4acc38730 [Type checker] Drop parameter 'inout' types in a few more places.
Follow-up to my earlier changes to drop 'inout' types when cloning parameter
lists, we also need to deal with substitutions into those parameter types.
This is an artifact of us having mostly---but not entirely---removed
InOutType from the AST. Fixes rdar://problem/34818336.
2017-10-04 21:18:05 -07:00
Doug Gregor
0609785b64 [AST] Strip InOutType when cloning a parameter.
Fixes rdar://problem/34789779, where initializer inheritance was breaking
in the presence of 'inout' parameters.
2017-10-04 10:59:16 -07:00
Alex Hoppen
f35f29d9cf [Diag] Change function diagnostics to take a DeclName parameter
This provides richer error messages that include the function's
parameters
2017-07-01 13:37:08 +02: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
68dc9455e7 Sema: Remove redundant mapType{Into,OutOf}Context() calls
The code in recordTypeWitness() seemed to be completely bogus;
it already receives a type written in terms of the archetypes
of the adoptee's context, so mapTypeOutOfContext() did nothing
here, because it was using the wrong substitutions.

The logic for synthesizing designated initializers was also
slightly wrong if the class was nested inside a generic
function.

Finally, interface and contextual types of a derived rawValue
were flipped around.
2016-07-02 05:39:12 -07:00
Slava Pestov
0ff0f3c5b9 Sema: Generic classes and subclasses of generic classes now inherit required initializers
Initializers are inherited by synthesizing an implicit decl which
delegates to super.init(). Previously this was only done if the
class and superclass were concrete.

The only thing missing was that we weren't computing an interface
type for the synthesized constructor. There are two steps to this:

- First, we must map the contextual types of the superclass
  initializer's ParamDecls to the subclass generic context.

- Second, we must set the interface type by calling the new
  configureInterfaceType() method, extracted from from
  validateGenericSignature().

Note that configureInterfaceType() now uses the new
AbstractFunctionDecl::hasThrows() flag to set the 'throws' bit on
the function type. Previously, validateGenericFuncSignature()
would look at getThrowsLoc().isValid(), which is not correct for
imported, implicitly-generated or de-serialized decls that 'throw',
because none of those have source location information.

We still don't allow inheriting initializers which have their
own generic parameter list, like 'init<T>(t: T) {...}'. That
requires a little bit more refactoring.

Progress on <rdar://problem/23376955>.
2016-05-21 12:51:51 -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
Chris Lattner
cf2e7f6f45 Fix SR-718: Type mismatch reported as extraneous parameter
The issue here is that the constraint solver was deciding on
FixKind::RelabelCallTuple as the fix for the problem and emitting the
diagnostic, even though there were two different fixes possible.

CSDiags has the infrastructure to support doing doing the right thing
here, but is only being used for ApplyExprs, not SubscriptExprs.

The solution is to fix both problems: remove FixKind::RelabelCallTuple,
to let CSDiags handle the problem, and enhance CSDiags to treat
SubscriptExpr more commonly with ApplyExpr.  This improves several cases
where the solver was picking one solution randomly and suggesting that
as a fix, instead of listing that there are multiple different solutions.
2016-02-12 17:19:54 -08:00
David Farler
93b6962478 Warn when using 'var' bindings in function parameters
These will no longer be allowed in a future Swift release.

rdar://problem/23172698
2015-11-03 17:24:20 -08:00
Chris Lattner
ada5487153 add fixit tests to random other tests.
Swift SVN r31006
2015-08-04 20:35:36 +00:00
Chris Lattner
e4b6afb9ae Start moving the testsuite to the "_ = foo()" idiom for evaluating an
expression but ignoring its value.  This is the right canonical way to do
this.  NFC, just testsuite changes.



Swift SVN r28638
2015-05-15 20:15:54 +00:00
Chris Lattner
7059871abf Convert some 'var' bindings to 'let' when they are not mutated, some
var/let bindings to _ when they are never used, and use some values that
are only written.  This is a testsuite cleanup, NFC. More to come.


Swift SVN r28406
2015-05-11 00:20:55 +00:00
Dmitri Hrybenko
971718b45c stdlib: mark declarations that we plan to remove as deprecated
Swift SVN r27437
2015-04-17 18:15:00 +00:00
Chris Lattner
59c22383fb Rework PatternBindingDecl to maintain a list of pattern/initexpr pairs inside of it.
Previously, a multi-pattern var/let decl like:
  var x = 4, y = 17

would produce two pattern binding decls (one for x=4 one for y=17).  This is convenient
in some ways, but is bad for source reproducibility from the ASTs (see, e.g. the improvements
in test/IDE/structure.swift and test/decl/inherit/initializer.swift).

The hardest part of this change was to get parseDeclVar to set up the AST in a way
compatible with our existing assumptions. I ended up with an approach that forms PBDs in 
more erroneous cases than before.  One downside of this is that we now produce a spurious
  "type annotation missing in pattern"
diagnostic in some cases.  I'll take care of that in a follow-on patch.





Swift SVN r26224
2015-03-17 16:14:18 +00:00
Dmitri Hrybenko
e460eb6264 Revert "[stdlib] Replace aString.toInt() with Int(aString)"
This reverts commit r25636.  It depends on integer parsing APIs, which
are being moved to SwiftExperimental.

Swift SVN r25889
2015-03-09 19:04:18 +00:00
Dave Abrahams
47288e357b [stdlib] Replace aString.toInt() with Int(aString)
Swift SVN r25636
2015-02-28 06:01:03 +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
5fc8ac7fd1 Require the 'override' keyword for initializers that override designated initializers.
Swift SVN r20490
2014-07-24 15:38:33 +00:00
Jordan Rose
14196453cc Add a special diagnostic when a type has no accessible initializers.
Rather than just saying "'Foo' is not constructible with '()'", say
"'Foo' cannot be constructed because it has no accessible initializers",
which would help framework authors realize what they did wrong.

<rdar://problem/17717714>

Swift SVN r20232
2014-07-20 19:52:24 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Doug Gregor
ea7e70bbf7 Automatically inherit subobject initializers when none are explicitly defined.
If a subclass defines no subobject initializers and all of its stored
properties have initial values, "inherit" all of the subobject
initializers of its superclass by creating a new initializer with the
same signature that overrides (and chains to) the corresponding
subobject initializer of its parent. Do this instead of blindly
creating a default initializer.

Note that we aren't yet doing this for generic initializers. That will
be a separate step.

Swift SVN r14995
2014-03-13 18:43:30 +00:00