Commit Graph

3469 Commits

Author SHA1 Message Date
Paul Berry 1ffba32609 Rework type inference logic to avoid redundant constraint gathering.
Previously, the analyzer would perform downwards and upwards inference
using separate GenericInferrer objects.  This meant that any
constraint gathering work performed during downwards inference had to
be repeated during upwards inference.

This change avoids the extra work by using a single GenericInferrer
object for both downwards and upwards inference.  It also cleans up
the API for GenericInferrer a bit.

Change-Id: Idc5deed96c18ffc89aeb8ba4e5e95942843dae11
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/236660
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-03-14 15:05:18 +00:00
Danny Tuppeny 0de43ae5f7 [analysis_server] Make CompilationUnitElement.lineInfo non-nullable
Change-Id: Ia42e2a2fd153b5af167588b9d4d473d1f998a67b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/235880
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-03-10 00:19:15 +00:00
Paul Berry 1cdfaa8587 Consolidate type inference logic for invocations.
Moves all of the analyzer's type inference logic for invocations into
a single `resolveInvocation` method, defined on an abstract base class
`InvocationInferrer`.  There are concrete derived classes to
specialize this logic for all of the types of AST nodes require this
sort of inference (Annotation, ExtensionOverride,
FunctionExpressionInvocation, InstanceCreationExpression,
MethodInvocation, RedirectingConstructorInvocation, and
SuperConstructorInvocation), and the special logic for each node type
is slotted into the core algorithm using virtual dispatch.

In addition to making the code more maintainable by reducing code
duplication, this change paves the way toward modifying the core
algorithm to allow inference information to flow between arguments in
a generic function call
(https://github.com/dart-lang/language/issues/731).

Also partially addresses #48500 (Expression.staticParameterElement
sometimes points to a synthetic element).

Change-Id: I82788d58a62b6555589da16163317b6bbddd53c1
Bug: https://github.com/dart-lang/language/issues/731, https://github.com/dart-lang/sdk/issues/48500
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234864
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-03-06 15:07:42 +00:00
Konstantin Shcheglov c9c980ab59 Remove deprecated analyzer/lib/src/generated/type_system.dart
Change-Id: I865ec37770fa6f4a9011fc2520ff015c77f63243
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/235172
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-03-03 21:57:52 +00:00
Konstantin Shcheglov 26a3247fb4 Issue 48502. Report RETHROW_OUTSIDE_CATCH when new executable inside catch.
Bug: https://github.com/dart-lang/sdk/issues/48502
Change-Id: Iddab4ff30eca7da4891916ac051ad9a827a252e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/235170
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-03-03 21:50:11 +00:00
Danny Tuppeny 1e9fb81697 [analysis_server] Make CompilationUnit.lineInfo non-nullable
Change-Id: Ib628751a14dc3257cf7325432ab20f2bdb9d6f3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234290
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-03-03 06:59:00 +00:00
Konstantin Shcheglov 366ad77ee2 Report NON_FINAL_FIELD_IN_ENUM.
Change-Id: I6b481cd5cd02d4dbfdb213fe25aae0423c1b06ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234913
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-03-02 23:52:30 +00:00
Konstantin Shcheglov d281ced782 Report FINAL_NOT_INITIALIZED_CONSTRUCTOR errors.
Change-Id: I1e0d0f503615a9b0fec8f66468e26aaa611c5cca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234326
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2022-02-24 21:30:46 +00:00
Paul Berry 514b8f36ff Change resolver to pass context types around entirely on the stack.
This change eliminates the methods `InferenceContext.setType`,
`InferenceContext.clearType`, and `InferenceContext.getContext`, in
favor of passing context types around on the stack.

This should improve performance (by avoiding map lookups in
`AstNodeImpl._propertyMap`) and should make it easier to understand
the behavior of context types in the debugger (by making them visible
in stack frames).

Change-Id: Idd672af60adbb7f32258ef5319761706485a0f63
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234113
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-24 17:57:23 +00:00
Paul Berry 2b8051d564 Migration: avoid introducing a cast on an implicit .call tearoff.
The migration engine resolves the ASTs for the code in question twice,
once with null safety features turned off, in order to build the
nullability graph, and then a second time with null safety features
turned off, in order to determine the precise type of every
subexpression and figure out where `!`s and casts need to be inserted.

The analyzer passes type inference contexts around by storing them on
AST nodes.  As a result, if a context type is associated with an AST
node the first time the code is resolved, and no context is stored the
second time it is resolved, the leftover contextual information gets
erroneously used by the second resolution pass.  Before this change,
this was happening for expressions that received `.call` tearoffs,
because during the second resolution pass, the expression was wrapped
inside an `ImplicitCallReference` node, and the logic for analyzing
such nodes didn't bother to clear the context when visiting the
subexpression.

This change fixes the problem by directly calling `analyzeExpression`
to visit the subexpression (allowing the correct context to be
explicitly provided).

Fixes #47848.

Bug: https://github.com/dart-lang/sdk/issues/47848
Change-Id: Ie22c2821a0e04c1fb685d2cad7f8675fa08ef986
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234080
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-23 21:23:33 +00:00
Paul Berry 45dca998ac Consolidate calls to InferenceContext.getContext.
This change moves all the call sites for `Inference.getContext` to the
top of `ResolverVisitor.visit` methods.  Any other methods that need
access to the inference context receive it as a parameter.

This is part of a larger effort to elimiate the use of
InferenceContext.getContext and InferenceContext.setType entirely.

Change-Id: Ie5b9dd3adf827a5b17b0f5662c5a7ed9c8e98069
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233863
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-23 17:13:43 +00:00
Johnni Winther cd41e43c48 [parser] Support 'augment' as a built-in identifier for augmentation libraries
This changes the way the 'augment' modifier is handled in the parser.
Instead of being special cased for class declarations, it is now a
built-in identifier recognized only when the scanner is configured to
support augmentation libraries.

The change supports the used of the 'augment' modifier on not only
class declarations but also mixin and member declarations, as needed
for supporting macros.

Change-Id: I2679d198dea360900cfc478fae9c1660702a8a02
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233887
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-23 16:17:42 +00:00
Paul Berry 1d096c23cf Simplify analyzer logic for .call tearoffs.
Previously, the job of determining whether a `.call` tearoff was
necessary for an expression fell to the expression that contained it.
This made things complicated for set, map, and list literals, because
it required the literal to be visited twice (once to resolve the
subexpressions, and another time to insert `.call` tearoffs).  With
this change, insertion of a `.call` tearoff is handled by the visitor
for the expression itself.

(Note that there are a few cases where we don't insert a `.call`
tearoff, or we do so based on a special type, based on the parent
expression.  The language team is considering removing these special
cases, but for now, we maintain the existing behavior.  We handle
these special cases by looking at `expression.parent`).

Change-Id: I85c813f8c105e3b962dd89d5a7fa8467506078ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232660
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-22 20:17:21 +00:00
Paul Berry f654af1fea Breaking analyzer change: always insert ImplicitCallReference nodes.
Previously, we only inserted these nodes when the
`constructor-tearoffs` feature was active, as a way of reducing the
risk of breaking analyzer clients; however this behavioral
inconsistency is not something we want to keep for the long term.

Note: even though this is technically a breaking change, we haven't
found any analyzer clients that are affected by it, so we're going
ahead and landing it without an analyzer version number bump.

Change-Id: I71f0fb2862b644dd1a81245bd12f5b7b9ca45857
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233653
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-22 16:43:21 +00:00
Paul Berry 77a4d88c06 Properly handle implicit .call tearoff on RHS of assignments.
Previously, when inserting an implicit `.call` tearoff on the RHS of
an assignment, both the analyzer and the CFE failed to properly
propagate the type of the tearoff to the static type of the assignment
expression.  This resulted in a soundness bug for compiled programs.

Fixes #48409.
Fixes #48410.

Bug: https://github.com/dart-lang/sdk/issues/48409, https://github.com/dart-lang/sdk/issues/48410
Change-Id: I489f38bd7cac4ebadd3746ec32c1ef0f73e18169
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233640
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-21 16:38:51 +00:00
Konstantin Shcheglov f784130fea Fix MISSING_REQUIRED_ARGUMENT for super-formal parameters.
Change-Id: I0ee3114e5d618fa16da42072c8bc15d7b86001c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233525
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-18 17:33:53 +00:00
Johnni Winther 2435848b13 [parser] Support 'augment' modifier on class declarations
This adds support for the 'augment' modifier on class declarations
needed for the static meta-programming prototype.

Change-Id: Iadd11f766a195076405f2803b2092199caf1ea8c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233180
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2022-02-18 09:39:23 +00:00
Konstantin Shcheglov 60b428e2b1 Deprecate superclass2, mixinTypes2, etc.
Change-Id: Ieaaeab57930cb93f5b6b1323efe63c3395b79993
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232742
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-17 02:20:42 +00:00
Paul Berry 8652944f72 Clean up how negated integer literals are type inferred.
Previously, when upon reaching the integer literal, we would check if
the parent was a PrefixExpression with an operator of `-`, and if so,
use the context type of the PrefixExpression to decide whether to do
an int->double conversion.  This CL moves the logic to the
PrefixExpressionResolver; we now pass down the appropriate context
when visiting the integer literal.

This makes the context handling for negated integer literals less of
an odd exception.

This is part of a larger effort to elimiate the use of
InferenceContext.getContext and InferenceContext.setType entirely.

Change-Id: I6ca63df1adcb706011c146c80c2576814a73926d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231326
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-10 18:36:51 +00:00
Konstantin Shcheglov b66ea5276f Use elements in GetterSetterTypesVerifier, support fields.
Change-Id: I92376ace55845385e69742e0eaadcae407a71a53
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232228
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-09 22:36:48 +00:00
Konstantin Shcheglov e8c25a56b7 Include enum type parameters into the namespace when resolving identifiers.
Change-Id: I2804e3ace95313b5e2a99bcc679d8965dfff26c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232224
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-09 21:48:31 +00:00
Konstantin Shcheglov 1acf0dce85 Report ENUM_INSTANTIATED_TO_BOUNDS_IS_NOT_WELL_BOUNDED
Change-Id: I4cef975da984b9bf1da64008292864b716b13e8f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232128
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-09 16:13:06 +00:00
Nate Bosch 33e174084a Replace Uri.scheme == with Uri.isScheme
Use `hasScheme` in place of comparing against the empty string, and
`isScheme` to compare against all other schemes.

TEST=No behavior changes.

Change-Id: Ifc9fd13c6cf37933ebd4a754c4b500dedbcb291b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231185
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Nate Bosch <nbosch@google.com>
2022-02-08 21:38:57 +00:00
Konstantin Shcheglov 7282a40c49 Report ILLEGAL_LANGUAGE_VERSION_OVERRIDE even when the package language version causes it.
Change-Id: I617d67ba06758e3f57d9ff0048a080d0a699fc96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232126
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-08 21:23:46 +00:00
Konstantin Shcheglov d8e2cdaeec Report WRONG_NUMBER_OF_TYPE_ARGUMENTS_ENUM and TYPE_ARGUMENT_NOT_MATCHING_BOUNDS for enums.
Change-Id: Icac828fa09d7565974727521c27b5cd4daa7e0f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232089
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-08 19:50:36 +00:00
Konstantin Shcheglov f6ebb50359 Report ENUM_CONSTANT_WITH_NON_CONST_CONSTRUCTOR
Change-Id: I3962553ccaa881db761e87fdd97ce47a65db4b2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232124
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-08 19:15:28 +00:00
Konstantin Shcheglov 62488444c9 Report INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR for factory redirections.
Change-Id: I02f6f3f374cd00b24722b8eb5498aaab33b1a7fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232121
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-08 17:25:06 +00:00
Konstantin Shcheglov 1d7d5a6dcf Verify the number and types of enum constant arguments.
Change-Id: Id51ca6081bb9a1ab85217457bca67cae8adce710
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232033
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-08 16:16:06 +00:00
Konstantin Shcheglov 63f34ab810 Report UNDEFINED_ENUM_CONSTRUCTOR_NAMED/UNNAMED
Change-Id: I02b8a2d9d3988cc0c281a8d251b9670e378b3561
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232023
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-07 23:27:14 +00:00
Brian Wilkerson 867e155ff6 Merge two error codes
I was thinking about unifying these two codes for documentation purposes,
but then I wondered whether we might not want to unify them for reporting
purposes too. The reason I think it might be better to unify them is
because (a) they really represent a single problem (missing required
arguments) and (b) we were previously reporting the same problem multiple
times.

Change-Id: Iecf2865e67d61b03a1e1f56781e94e283d2a08e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232022
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2022-02-07 23:10:06 +00:00
Ilya Yanok 3c16fdd3b0 Fix type inference for yield* inside method w/o declared return type
This was broken after
https://dart-review.googlesource.com/c/sdk/+/230948, the example would
be

```dart
class A {
   m() sync* {
     yield* [1];
   }
 }
```

Inferred type for expression in `yield*` statement is
`List<FutureOr<dynamic>>` after the above CL, while I'd expect it
to be `List<int>`.

The change modified the behaivor while passing the imposed
return type a bit: `InferenceContext.setType` resets the type to `null`
if it's `dynamic`, while the logic that passes the type down explicitly
doesn't do that. My change restores the behavior of resetting the
imposed type to `null` if it's `dynamic`.

Interestingly enough, this is not a problem for function declarations:
`FunctionExpressionResolver.resolve(FunctionExpressionImpl)`
has special clause that resets the imposed type to null. But
for reasons I don't understand `FunctionExpressionResolver` is
used for function declarations but not for method declaration.

Change-Id: I63cfde01f067c25442afed64843861d09c7474a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231702
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
2022-02-07 19:34:18 +00:00
Konstantin Shcheglov c99e3af906 Report duplicate declarations for enums.
Change-Id: I2bda7ea3116a4ea8c65024c8ec4b5981e7d93c19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231746
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-05 02:07:30 +00:00
Konstantin Shcheglov 14bead484c Report more enum hierarchy errors for enums.
Change-Id: I9ffc41ce9cbc9a51b059dc8a891e59420232d047
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231536
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-04 18:51:39 +00:00
Konstantin Shcheglov 1e66a8a079 Report more hierarchy diagnostics for enums.
Change-Id: If2c4ef3604fadfaa6d3d5af992f61a6a819a5b01
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231528
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-03 23:39:26 +00:00
Konstantin Shcheglov 33b3c1d6c6 Report ILLEGAL_LANGUAGE_VERSION_OVERRIDE, when 'sourceLanguageConstraint' is set.
Change-Id: Ibbd786090a5a1a61da11f1e9de754202bdc454d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231322
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-02 20:20:39 +00:00
Konstantin Shcheglov 64001abe3e Add ConstructorElement.isGenerative and ClassElement.isDartCoreEnum
Change-Id: I0d7391fe02e450cb3ac33fd6abbe33a3561243ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231280
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-02 17:32:19 +00:00
Paul Berry bf51e35c46 Consolidate remaining calls to InferenceContext.setType.
Now that we only use InferenceContext.setType for expressions, this
change consolidates all the call sites to just two places:

- The method ResolverVisitor.analyzeExpression, which is used when
  recursively analyzing subexpressions inside expressions and
  statements.

- The method InferenceContext.setTypeFromNode, which is used during
  AST rewrites to transfer context information from the original node
  to the rewritten node.

This is part of a larger effort to elimiate the use of
InferenceContext.getContext and InferenceContext.setType entirely.

Change-Id: Id236bcb1247c09b740bbbad41cb74ecda301cc86
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231181
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-02 16:54:00 +00:00
Paul Berry 58a42b5cfc Stop storing contextual information on FunctionBody nodes.
Instead of using InferenceContext.getContext and
InferenceContext.setType to associate type inference information with
VariableDeclaration nodes, we pass the information on the stack using
a new FunctionBodyImpl.resolve method.  This should be more efficient
for two reasons: it avoids a map lookup, and it avoids the double
dispatch traditionally associated with calling a visitor.  It should
also make the code easier to reason about (since it makes the flow of
data in the type inference process more explicit).

This is part of a larger effort to elimiate the use of
InferenceContext.getContext and InferenceContext.setType entirely.

Change-Id: I8a3f3be940acdcd0a2c4ad8ec37b41bafe25c952
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230948
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-02 16:04:39 +00:00
Paul Berry e1e3bcce17 Stop storing contextual information on VariableDeclaration nodes.
Instead of using InferenceContext.getContext and
InferenceContext.setType to associate type inference information with
VariableDeclaration nodes, we directly look up the variable type when
we need it.  This should be more efficient (since it avoids a map
lookup), and it should make the code easier to reason about (since it
makes the flow of data in the type inference process more explicit).

This is part of a larger effort to elimiate the use of
InferenceContext.getContext and InferenceContext.setType entirely.

Change-Id: I01262fb3c3e6789ee9da924e731d86d99ce3f4de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230946
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-02 14:59:49 +00:00
Konstantin Shcheglov 22a8295295 Report INVALID_REFERENCE_TO_GENERATIVE_ENUM_CONSTRUCTOR instead of INSTANTIATE_ENUM when enhanced-enums.
Change-Id: I634b3e50641b2b696b4d9e164266b43fdc72f137
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231063
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-01 23:58:45 +00:00
Paul Berry 0d5eec26f1 Stop storing contextual information on ArgumentList nodes.
Instead of using InferenceContext.getContext and
InferenceContext.setType to associate type inference information with
ArgumentList nodes, we pass the contextual information around on the
stack.  This should be more efficient (since it avoids a map lookup),
and it should make the code easier to reason about (since it makes the
flow of data in the type inference process more explicit).

This is part of a larger effort to elimiate the use of
InferenceContext.getContext and InferenceContext.setType entirely.

Change-Id: I331792cf6d7289a27fc71edfc6af33cd1af5288c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230942
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-01 23:54:05 +00:00
Paul Berry 6117501cd6 Streamline context handling for collection literals.
Rather than do two passes over each collection literal (one to push
contexts down and a second pass to resolve), we pass the contexts down
on the stack during a single resolve pass.

I decided to create an extra data structure to hold the context
information (so I only had one thing to pass around on the stack
rather than four).  The extra allocation will carry a small
performance cost.  However, I was able to reduce the number of passes
over the collection literal from two to one, replace a chain of
is-tests with a virtual dispatch, and eliminate a double-dispatch in
some cases, so hopefully the benefit of those improvements will more
than offset the cost.

This is part of a larger effort to elimiate the use of
InferenceContext.getContext and InferenceContext.setType entirely.

Change-Id: I949c2c5ef99fc3395de3d67eaa8f326b7af5b158
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231062
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-01 23:42:45 +00:00
Konstantin Shcheglov dcc1b8bc18 Report NON_CONST_GENERATIVE_ENUM_CONSTRUCTOR.
Change-Id: I1a087a3b554d5d5439d43b0798d14a46310f1bfe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231048
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-01 18:18:55 +00:00
Konstantin Shcheglov 17d2a0b755 Report SUPER_IN_ENUM_CONSTRUCTOR.
Change-Id: I403b51eed9a0f685e56433a2b567b8a38a95e15b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231049
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-02-01 18:18:35 +00:00
Paul Berry 410442716d If a try block terminates, don't consider the contents of the finally block to be dead code.
Fixes #48258.

Bug: https://github.com/dart-lang/sdk/issues/48258
Change-Id: Icf88c659f3258a723970d89882b58c75f8eff6d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231043
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2022-02-01 13:32:36 +00:00
Konstantin Shcheglov 86383dd1af Build interfaces for enums.
Change-Id: I2e73761f46ac37d7bef6902575de031c9f401f6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230880
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-01-29 03:00:22 +00:00
Konstantin Shcheglov aa432071b6 Remove 'index' and 'name' parameters from enum constructors.
Change-Id: Id3fba669be70f830777fb3db1cfe31898e6df726
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230440
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-01-27 22:08:42 +00:00
Konstantin Shcheglov 51dfe64fb0 Don't report CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER for enum constructors.
Bug: https://github.com/dart-lang/sdk/issues/48232
Change-Id: I8621f04c67bf8f3ef3ec82945516613058b12029
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230321
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-01-27 17:46:38 +00:00
Konstantin Shcheglov e8d5008843 Update validation for final fields with const enum constructor.
For now just making it to not crash.

Change-Id: I415f0c7e17cc959f26f87acd2d662e7f6de3b39b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229780
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-01-25 05:37:26 +00:00
Konstantin Shcheglov 7162015869 Resolve enum constants to constructors.
Change-Id: Iace6dd63bd2071830436b070299991f4e811cdf6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229620
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2022-01-25 02:48:38 +00:00