Commit Graph

84 Commits

Author SHA1 Message Date
Hamish
48f08bdbc7 [Sema] Diagnose immediate deallocation of instances assigned to non-owning variables
When performing a binding/assignment to a weak or unowned variable/property from an initialiser call, emit a warning that the instance will be immediately deallocated.
2018-03-08 16:32:35 +00:00
Jordan Rose
449cd98997 Excise "Accessibility" from the compiler (3/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

Rename AccessibilityAttr to AccessControlAttr and
SetterAccessibilityAttr to SetterAccessAttr, then track down the last
few uses of "accessibility" that don't have to do with
NSAccessibility. (I left the SourceKit XPC API alone because that's
supposed to be more stable.)
2017-08-28 13:27:59 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
Jordan Rose
5f30eac288 Excise "Accessibility" from the compiler (1/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the names of methods, fields, a few local
variables, and even a swift-ide-test flag. The full list is below.

accessibilityForDiagnostics -> accessLevelForDiagnostics
checkAccessibility -> checkAccess
checkGenericParamAccessibility -> checkGenericParamAccess
checkTypeAccessibility -> checkTypeAccess
checkWitnessAccessibility -> checkWitnessAccessibility
computeAccessibility -> computeAccessLevel
computeDefaultAccessibility -> computeDefaultAccessLevel
fixItAccessibility -> fixItAccess
getAccessibilityString -> getAccessLevelString
getAccessibilityStrictly -> getAccessLevelStrictly
getAccessibilityUID -> getAccessLevelUID
getActualAccessibility -> getActualAccessLevel
getDefaultAccessibility -> getDefaultAccessLevel
getMaxAccessibility -> getMaxAccessLevel
getOverridableAccessibility -> getOverridableAccessLevel
getRawStableAccessibility -> getRawStableAccessLevel
getSetterAccessibility -> getSetterFormalAccess
hasAccessibility -> hasAccess
hasDefaultAccessibility -> hasDefaultAccessLevel
inferAccessibility -> inferAccessLevel
inferDefaultAccessibility -> inferDefaultAccessLevel
inferSetterAccessibility -> inferSetterAccessLevel
overwriteAccessibility -> overwriteAccess
overwriteSetterAccessibility -> overwriteSetterAccess
printAccessibility -> printAccess
requiredAccessibilityForDiagnostics -> requiredAccessForDiagnostics
resolveAccessibility -> resolveAccessControl
setAccessibility -> setAccess
setSetterAccessibility -> setSetterAccess
setDefaultAndMaxAccessibility -> setDefaultAndMaxAccess
validateAccessibility -> validateAccessControl

Accessibility -> AccessLevel
AccessibilityFilter -> AccessFilter
IgnoreAccessibility -> IgnoreAccessControl
NL_IgnoreAccessibility -> NL_IgnoreAccessControl
PrintAccessibility -> PrintAccess
PrintInternalAccessibilityKeyword -> PrintInternalAccessKeyword
SetterAccessibility -> SetterAccessLevel

setterAccessibility -> setterAccess
storedPropertyAccessibility -> storedPropertyAccess

-print-accessibility -> -print-access
2017-08-28 11:11:57 -07:00
Brian King
b389fc3ef5 Code review feedback 2017-01-26 18:00:00 -05:00
Brian King
36e36a1551 Align TLCD checking better with existing approach 2017-01-26 09:59:27 -05:00
Brian King
6091cda408 Run the VarDeclUsageChecker on top level declarations 2017-01-24 22:50:28 -05:00
Slava Pestov
aa63f83f51 Sema: Extract availability code into TypeCheckAvailability.cpp 2017-01-06 18:59:34 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Doug Gregor
0c0517f997 [Type checker] Don't drop "delayed" conformance diagnostics after a source file.
The protocol conformance checker tries to delay the emission of
diagnostics related to the failure of a type to conform to a protocol
until the source file that contains the conformance is encountered, to
provide redundant diagnostics. However, if a file produced only such
delayed diagnostics, such that all diagnostics were suppressed,
invalid ASTs could slip through to later stages in the pipeline where
they would cause verification errors and crashes. This happens
generally with whole-module-optimization builds, where we are re-using
an ASTContext when typing multiple source files.

This is a narrow-ish fix to stop dropping diagnostics from one source
file to the next in whole-module-optimization builds. Part of
rdar://problem/29689007.
2016-12-16 15:15:17 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Aleksey Gaponov
f51b2d12c4 [SR-2209] Make a real AccessScope class and use it in access checking.
1. Add new AccessScope type that just wraps a plain DeclContext.
2. Propagate it into all uses of "ValueDecl::getFormalAccessScope".
3. Turn all operations that combine access scopes into methods on AccessScope.
4. Add the "private" flag to distinguish "private" from "fileprivate"
scope for top-level DeclContext.
2016-11-04 12:42:38 +01:00
Graydon Hoare
cec8f58197 Add swift::diagnoseDeclAvailability, use in TypeCheckType. 2016-10-12 11:21:30 -07:00
Rintaro Ishizaki
65f3ba5dbb [Sema] Unify fix-it logic for enclosing trailing closure in argument parens (#4961)
`tryDiagnoseTrailingClosureAmbiguity` and `checkStmtConditionTrailingClosure`
had similar logic.
Added swift::fixItEncloseTrailingClosure function.
2016-09-24 18:33:40 +09:00
Jordan Rose
d89c232f59 Add empty parens to var-to-function renames, take two. (#4938)
This time, propagate the decl marked deprecated or unavailable through
to the fix-it, so we can be sure it's a var.

https://bugs.swift.org/browse/SR-1649
2016-09-23 14:56:08 -07:00
Jordan Rose
f65ad810df Check protocol witnesses using access scopes. (#4176)
...rather than relying on the access-as-spelled, which may be greater
than the effective access due to parent scopes.

(Some of this will get cleaned up with SR-2209.)

rdar://problem/27663492
2016-08-11 14:30:09 -07:00
Jordan Rose
258e2bb45c Provide fix-its when implementing a protocol method with bridged types. (#2799)
This is the protocol version of 7bfdd4a2: if a protocol requirement
has a newly-bridged type (say, 'URL' instead of 'NSURL'), then any
conforming types will need to update their implementations of the
requirement. Reuse the override-checking mechanism to do so when
we're reasonably confident about it.

This slots the checking into the existing protocol diagnostics, which
doesn't result in the best user experience.

    note: protocol requires property 'prop' with type 'Refrigerator?'
      var prop: Refrigerator? { get }
          ^
    note: candidate has non-matching type 'APPRefrigerator?'
      var prop: APPRefrigerator? {
          ^     ~~~~~~~~~~~~~~~~
                Refrigerator?

But we can come back and improve that later; right now this is better
than nothing.

rdar://problem/26237030
2016-06-01 14:03:21 -07:00
Jordan Rose
5343b594de Don't try to apply fix-its for renamed operators.
...or renaming to operators, unless we're sure the original thing was
an operator expression. There are just a lot of ways this can be
screwed up.

(Some cases of this can certainly be implemented. I may file a
StarterBug later.)
2016-05-20 16:58:50 -07:00
Jordan Rose
2966d99dbb Fix a use-after-delete in ec59bf9f caught by ASan. 2016-04-29 10:33:01 -07:00
Jordan Rose
797260939e Handle argument labels in @available(renamed:"...")
Fixes SR-1008 / rdar://problem/25276961
2016-04-28 20:21:30 -07:00
Jordan Rose
ec59bf9f18 Move helper function 'diagnoseArgumentLabelError' to MiscDiagnostics.
Groundwork for SR-1008. No functionality change.
2016-04-28 20:21:30 -07:00
Andrew Trick
ff02652108 Move enums into AttrKind.h.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.

PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
2016-02-26 21:10:22 -08:00
practicalswift
a3f857ca7b [gardening] Add "-*- C++ -*-" to header files currently missing it 2016-01-23 11:53:05 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Jordan Rose
6b12b9130e Disallow nesting 'self.init' or 'super.init' inside other expressions.
In addition to being confusing, it makes it harder to implement
'try? self.init(...)' properly. (Next commit!)

Swift SVN r31034
2015-08-05 22:17:41 +00:00
Chris Lattner
9ae1ff707c Add a new DisableStructuralChecks option to typeCheckExpr which allows CSDiag to
avoid emitting this diagnostics.  They are always irritating to it because they
are duplicative with whatever the actual type constraint problem is.  It also
interferes with there recursive structure of the problem.

Disabling them also allows us to shorten the black list of expr nodes that cannot
be handled in typeCheckIndependentSubExpression.



Swift SVN r30122
2015-07-11 22:28:40 +00:00
Chris Lattner
ddd6192094 Implement 3 prominent feature requests:
<rdar://problem/15975935> warning that you can use 'let' not 'var'
<rdar://problem/18876585> Compiler should warn me if I set a parameter as 'var' but never modify it
<rdar://problem/17224539> QoI: warn about unused variables

This uses a simple pass in MiscDiagnostics that walks the body of an
AbstractFunctionDecl.  This means that it doesn't warn about unused properties (etc),
but it captures a vast majority of the cases.

It also does not warn about unused parameters (as a policy decision) because it is too noisy,
there are a variety of other refinements that could be done as well, thoughts welcome.



Swift SVN r28412
2015-05-11 06:26:05 +00:00
Jordan Rose
8f520414b7 [Accessibility] A private class cannot contain public methods.
There's no meaningful way in which these methods are public, since they
can't be accessed through any value of the type

<rdar://problem/17647878>

Swift SVN r20224
2014-07-20 17:26:24 +00:00
Jordan Rose
faa0fc4e41 [Accessibility] Setter requirements must be public for public conformances.
That is, if a protocol specifies that a property or subscript is settable,
check the accessibility of the conforming type's setter.

Swift SVN r19714
2014-07-09 00:07:45 +00:00
Jordan Rose
d545ac1623 [Accessibility] @required initializers must be as accessible as the type.
Swift SVN r19383
2014-06-30 23:38:36 +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
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