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
This commit is contained in:
Chris Lattner
2015-05-11 06:26:05 +00:00
parent acf5a426bb
commit ddd6192094
14 changed files with 599 additions and 43 deletions

View File

@@ -2265,6 +2265,28 @@ ERROR(availability_declaration_less_available_than_protocol, sema_avail,
NOTE(availability_protocol_requirement_here, sema_avail, none,
"protocol requirement here", ())
//------------------------------------------------------------------------------
// Variable usage diagnostics
//------------------------------------------------------------------------------
WARNING(pbd_never_used, sema_varusage, none,
"initialization of %select{variable|immutable value}1 %0 was never used"
"; consider replacing with assignment to '_' or removing it",
(Identifier, unsigned))
WARNING(variable_never_used, sema_varusage, none,
"%select{variable|immutable value}1 %0 was never used; "
"consider replacing with '_' or removing it",
(Identifier, unsigned))
WARNING(variable_never_mutated, sema_varusage, none,
"%select{variable|parameter}1 %0 was never mutated; "
"consider changing to 'let' constant",
(Identifier, unsigned))
WARNING(variable_never_read, sema_varusage, none,
"%select{variable|parameter}1 %0 was written to, but never read",
(Identifier, unsigned))
#ifndef DIAG_NO_UNDEF
# if defined(DIAG)
# undef DIAG