Commit Graph

6 Commits

Author SHA1 Message Date
Robert Widmann
8c73b7db58 Define NamingPatternRequest
Use it to provide an idealized API for the VarDecl case in validateDecl.

In reality, a lot of work is needed to rationalize the dependency
structure of this request.  To start, the callers of
typeCheckPatternBinding must be eliminated piecemeal.  Once that is
done, the AST should introduce pattern binding decls along all the
places where getParentStmt() used to apply.
2019-10-17 09:40:45 -07:00
Robert Widmann
742f6b2102 Drastically Simplify VarDecl Validation
This is an amalgam of simplifications to the way VarDecls are checked
and assigned interface types.

First, remove TypeCheckPattern's ability to assign the interface and
contextual types for a given var decl.  Instead, replace it with the
notion of a "naming pattern".  This is the pattern that semantically
binds a given VarDecl into scope, and whose type will be used to compute
the interface type. Note that not all VarDecls have a naming pattern
because they may not be canonical.

Second, remove VarDecl's separate contextual type member, and force the
contextual type to be computed the way it always was: by mapping the
interface type into the parent decl context.

Third, introduce a catch-all diagnostic to properly handle the change in
the way that circularity checking occurs.  This is also motivated by
TypeCheckPattern not being principled about which parts of the AST it
chooses to invalidate, especially the parent pattern and naming patterns
for a given VarDecl.  Once VarDecls are invalidated along with their
parent patterns, a large amount of this diagnostic churn can disappear.
Unfortunately, if this isn't here, we will fail to catch a number of
obviously circular cases and fail to emit a diagnostic.
2019-10-14 12:06:50 -07:00
Anthony Latsis
4099e85da6 [Diagnostics & Tests] SR-6052 Prevent nil capitalization (#16256)
And provide better semantic background by surrounding 'nil' in ticks when it is referred to as a value

Added missing tests for certain cases involving nil capitalization
2018-05-03 09:10:30 -07:00
Robert Widmann
788f65bdf0 Bail on nil literal diagnostics if the source is Optional 2018-04-03 01:51:59 -04: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
Jordan Rose
405bfdc33b [Sema] Add a fix-it for non-optional bindings initialized with nil.
<stdin>:1:16: error: nil cannot initialize specified type 'Int'
var foo: Int = nil
               ^
<stdin>:1:10: note: add '?' to form the optional type 'Int?'
var foo: Int = nil
         ^
            ?
2016-04-21 13:36:54 -07:00