Commit Graph

591 Commits

Author SHA1 Message Date
Joe Groff
cf9e0d2624 Sema: Introduce metatype-to-object conversions.
Allow class metatypes (including class-constrained existential metatypes) to be treated as subtypes of AnyObject, and single-@objc protocol metatypes to be treated as subtypes of the Protocol class from objc. No codegen support yet, so this is hidden behind a frontend flag for now.

Swift SVN r18810
2014-06-11 23:06:23 +00:00
Doug Gregor
67ca1c9ea1 Implement the new casting syntaxes "as" and "as?".
There's a bit of a reshuffle of the ExplicitCastExpr subclasses:
  - The existing ConditionalCheckedCastExpr expression node now represents
"as?". 
  - A new ForcedCheckedCastExpr node represents "as" when it is a
  downcast.
  - CoerceExpr represents "as" when it is a coercion.
  - A new UnresolvedCheckedCastExpr node describes "as" before it has
  been type-checked down to ForcedCheckedCastExpr or CoerceExpr. This
  wasn't a strictly necessary change, but it helps us detangle what's
  going on.

There are a few new diagnostics to help users avoid getting bitten by
as/as? mistakes:
  - Custom errors when a forced downcast (as) is used as the operand
  of postfix '!' or '?', with Fix-Its to remove the '!' or make the
  downcast conditional (with as?), respectively.
  - A warning when a forced downcast is injected into an optional,
  with a suggestion to use a conditional downcast.
  - A new error when the postfix '!' is used for a contextual
  downcast, with a Fix-It to replace it with "as T" with the
  contextual type T.

Lots of test updates, none of which felt like regressions. The new
tests are in test/expr/cast/optionals.swift. 

Addresses <rdar://problem/17000058>


Swift SVN r18556
2014-05-22 06:15:29 +00:00
Chris Lattner
183b7e3790 fix <rdar://problem/16955318> Observed variable in a closure triggers an assertion
Swift SVN r18419
2014-05-19 14:37:38 +00:00
Doug Gregor
f477f061fe Replace ArrayDowncastConversionExpr with ArrayDowncastExpr.
Array downcast is an explicit cast written "x as U[]", not an implicit
conversion, so make it a subclass of ExplicitCastExpr. The only
effective change here is that we retain the location of the "as" and
the type as written in the AST. No semantic change.



Swift SVN r18391
2014-05-19 04:41:42 +00:00
Doug Gregor
d360ecd4f7 Extend availability checking to other expressions that have declarations.
We weren't diagnosing initializer delegation/chaining, subscripts, or
(the one that got me concerned) members accessed through AnyObject.

Swift SVN r18271
2014-05-17 20:51:01 +00:00
Chris Lattner
1b3f588d95 fix <rdar://problem/16941124> Overriding property observers warn about using the property value "within its own getter"
This is a regression introduced in r18184 which cased warnings on loads from
a property in its willSet/didSet.


Swift SVN r18210
2014-05-16 20:42:50 +00:00
Chris Lattner
cf55f7edd5 fix:
<rdar://problem/16264989> property not mutable in closure inside of its willSet
and:
<rdar://problem/16826319> willSet immutability behavior is incorrect

by changing how we handle immutability of an observing property within its willSet.
Instead of trying to model it as an rvalue, just model it as an lvalue (which it is)
and diagnose the problem with a warning in MiscDiagnostics.



Swift SVN r18184
2014-05-16 06:32:33 +00:00
Joe Pamer
1e5b9116d4 More array casting work:
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>

Swift SVN r17957
2014-05-12 20:49:42 +00:00
Joe Pamer
2eedc06d66 Begin adding plumbing for the type checker to accept "forward" bridged array conversions. (rdar://problem/16540403)
Swift SVN r17640
2014-05-07 19:45:37 +00:00
Joe Pamer
86b79d6bd3 Some code cleanup for array upcast conversions. (Part 2 of the fix for rdar://problem/16540403)
Swift SVN r16837
2014-04-25 19:52:06 +00:00
Joe Pamer
066f5e6da5 Allow for simple upcast conversions between array types. (Part 1 of the fix for rdar://problem/16540403)
Swift SVN r16836
2014-04-25 19:52:05 +00:00
Joe Groff
8f51b0e738 Revert "wip"
This reverts commit r16662. Fat fingers.

Swift SVN r16663
2014-04-22 21:50:52 +00:00
Joe Groff
4a81e48ef8 wip
Swift SVN r16662
2014-04-22 21:46:36 +00:00
Chris Lattner
78e8d3f0a9 rename the MetatypeExpr AST node to DynamicTypeExpr now that it is only
used by the "foo.dynamicType" syntax.


Swift SVN r16658
2014-04-22 20:10:11 +00:00
Chris Lattner
7f3d88632d Introduce a new AST node, named TypeExpr, which will be formed by sema
when resolving identifiers into types.  This will eventually allow us to
solve annoying issues like rdar://15295763&15588967 by better modeling
what we already have.


Swift SVN r16620
2014-04-21 16:10:11 +00:00
John McCall
9000278dcd Introduce MetatypeErasureExpr for erasing metatype
values into existential metatypes.  Erase thin metatypes
correctly in SILGen.

rdar://16610078

Swift SVN r16477
2014-04-17 22:31:47 +00:00
Ted Kremenek
d8c9a2ec8a Emit message for unavailable declarations (not just types).
Swift SVN r16401
2014-04-16 06:52:08 +00:00
Chris Lattner
7e121632ef Expand checking for implicit uses of self in closures to include method calls, and add
a fallback to catch anything else that is missed.  This resolve the rest of:
<rdar://problem/16193162> Require specifying self for locations in code where strong reference cycles are likely



Swift SVN r16319
2014-04-14 15:39:35 +00:00
Joe Groff
3bad92b342 AST: Remove the stopgap BridgeToBlockExpr and handle block <-> non-block conversions freely as function conversions.
Teach SILGen to handle function representation changes as part of function conversion instead of needing to be spoonfed a special expr for the purpose. Handle representation changes in both directions to and from blocks using the same logic as the bridging conversions.

Swift SVN r16318
2014-04-14 15:00:34 +00:00
Joe Groff
8f1c2d1e79 Sema: Implement type-checking for inout writeback conversion.
Add a third branch to the constraint system for '&x' expressions that allows conversion from an lvalue to a type via an additional writeback step:

- Add an LValueConversionExpr node that converts from @lvalue T to @lvalue U, given a pair of functions that convert T -> U and U -> T, to represent the writeback temporary.
- Allow conversion in an inout expression from @lvalue T to a type U that has the following members:

  static func __writeback_conversion(Builtin.RawPointer, T.Type) -> U
  static func __writeback_conversion_get(T) -> V
  static func __writeback_conversion_set(V) -> T

which builds a solution that produces an LValueConversion from the get/set pair before passing the pointer to the writeback temporary off to the conversion function.

Swift SVN r15764
2014-04-02 00:17:51 +00:00
Ted Kremenek
16ffbc6f3a Extend @availability(*,unavailable) checking to protocol methods.
Protocols can declare methods as being unavailable, as they do
in NSObjectProtocol (e.g., 'retain').  We both need to flag these
uses, but understand this for protocol conformance.  For protocol
conformance, treat unavailable methods as if they were marked
optional.  The compiler will not allow you to use these methods
anyway.

This finishes up support for:

    <rdar://problem/16331335> Ban ObjC ARC entry points

Swift SVN r15644
2014-03-30 07:11:39 +00:00
Joe Groff
46f77c6181 Sema: Build the AST for inout address conversions.
Add two new AST node types:

- InOutConversionExpr, which represents an '&x' expression that involves inout conversion. This will be a signal to SILGen not to introduce a writeback scope for the nested conversion call.

- LValueToPointerExpr, which represents the primitive '@lvalue T' to 'RawPointer' conversion that produces the argument to the inout conversion.

Build an InOutConversionExpr AST when an inout expression is resolved by a conversion to an BuiltinInOutAddressConvertible type.

Swift SVN r15594
2014-03-29 02:50:25 +00:00
Ted Kremenek
b9ac56302c Wire up initial diagnostics for checking 'unavailable' declarations.
There's a lot of detail work to do here, and obviously more
test cases.

Swift SVN r15510
2014-03-26 15:05:13 +00:00
Joe Groff
45eadd1d9b Rename AddressOfExpr to InOutExpr.
The "address" is an implementation detail; formally, it turns an lvalue into an inout parameter.

Swift SVN r15458
2014-03-25 16:28:28 +00:00
Chris Lattner
3348c46bf7 implement: <rdar://problem/16193162> Require specifying self for locations in code where strong reference cycles are likely
This requires that property references have an explicit "self." qualifier when in an
explicit closure expression, since self will be captured, not the property.

We don't do the same for autoclosures.  The logic here is that autoclosures can't 
practically be used in capturing situations anyway, since that would be extremely 
surprising to clients.  Further, forcing a syntactic requirement in an autoclosure
context would defeat the whole point of autoclosures: make them implicit.


Swift SVN r14676
2014-03-05 06:50:56 +00:00
Joe Groff
363a324984 Parse: Start parsing selector member references.
Parse 'x.y:z:' for at least two selector pieces as an UnresolvedSelectorExpr, and declare it unimplemented in Sema.

Swift SVN r14492
2014-02-28 01:47:32 +00:00
Joe Groff
4e87971d81 Disallow bare type references.
Diagnose a metatype reference that doesn't appear as part of a call or member reference, offering fixits to either default-construct the type or get at the metatype explicitly using '.self'. Also diagnose an attempt to refer to 'T.type' by fixiting it to '.self'.

Swift SVN r14433
2014-02-27 00:22:02 +00:00
Joe Groff
c0d8ae7c13 Parse 'x.self' as an identity expression.
Factor an IdentityExpr base class out of ParenExpr, and migrate most of the logic to see through ParenExprs to see through IdentityExprs instead. Add DotSelfExpr as a new subclass of IdentityExpr, produced by parsing 'x.self'.

Swift SVN r14381
2014-02-26 06:23:55 +00:00
Chris Lattner
d690a63a87 progress towards non-member observing properties:
- Add a "isDirectPropertyAccess" bit to DeclRefExpr, serving the 
   same purpose as MemberRefExprs for non-member properties.
 - Teach sema to synthesize correct non-member get/set implementations
   for observing properties.
 - Teach silgen to handle the isDirectPropertyAccess bit.



Swift SVN r13600
2014-02-06 22:34:37 +00:00
Chris Lattner
929ad99f08 Clean up and generalize the code pertaining to how a FuncDecl accessor
knows about the AbstractStorageDecl it works on.  NFC.



Swift SVN r12994
2014-01-27 17:57:38 +00:00
Chris Lattner
0dfb1ec790 introduce a new "IsDirectIVarAccess" bit to MemberRefExpr. Properties
that have both storage AND accessors are accessed by-default through
their accessors.  This bit indicates that a specific MRE should access
the storage instead.

Use this new bit in the synthesized getter/setter for "StorageObjC"
properties (it will also be used for other things in the future).
This also teaches SILGen about it.

One interesting aspect of this representation is that it makes it trivial
to add some expression syntax for directly accessing a store+computed 
property (e.g. ObjC properties, also someday didSet/willSet properties) 
someday if we care.  This would be analogous to the "self->ivar" syntax
in objc (vs self.ivar).  No, we will not use "->" for this. :-)

NFC since this is the use is still hidden under the -enable-new-objc-properties
staging option.



Swift SVN r12965
2014-01-26 06:08:53 +00:00
Jordan Rose
ae2868b482 Clean up comments in MiscDiagnostics.cpp.
No functionality change.

Swift SVN r12457
2014-01-17 02:58:25 +00:00
Jordan Rose
a6b616ad9e Accessing a property on another instance within the property's getter is okay.
There was a test for this but it wasn't really accurate. We now look for
MemberRefExprs where the base is literally just an implicit DeclRefExpr,
rather than something loaded from an implicit DeclRefExpr. This could break
with future AST refinement, but that will at least fail the test now.

Swift SVN r12456
2014-01-17 02:58:24 +00:00
Jordan Rose
77d5385c5d Warn on recursive mutation within a property setter.
The other half of <rdar://problem/14083624>

Swift SVN r12455
2014-01-17 02:58:23 +00:00
Jordan Rose
890df62a16 Warn on recursive computed variable access within its own getter.
Part of <rdar://problem/14083624>

Swift SVN r12454
2014-01-17 02:58:22 +00:00
Dmitri Hrybenko
c2c15e401b Disallow use of module values
rdar://15000289


Swift SVN r10546
2013-11-18 20:45:50 +00:00
Dmitri Hrybenko
9329ef41a5 Assigning variable to itself: fix a bug where we did not handle member
experssions with a complex base correctly

rdar://15405383


Swift SVN r10002
2013-11-06 20:05:14 +00:00
Anna Zaks
f8a79a56fb Address the reviews for r9982
Swift SVN r9999
2013-11-06 19:46:20 +00:00
Anna Zaks
c8ed1954f2 Issue a warning when returned expression is on the next line after the return keyword.
We still want to allow line wrapping, so only issue the warning when the indentation of the expression and the return keyword is the same.

radar://11945406

Swift SVN r9984
2013-11-06 02:00:13 +00:00
Dmitri Hrybenko
25c0c1b3b0 Self-assignment diagnostic: pass 'const Expr' where possible
Swift SVN r9981
2013-11-06 00:44:54 +00:00
Dmitri Hrybenko
61c067fe5f Implement a check in Sema to find self-assignment
rdar://14151649 suggests that it should be a warning, but I don’t see a reason
why it should not be an error.  We have no legacy code that relies on this.


Swift SVN r9976
2013-11-05 23:43:54 +00:00