Commit graph

69089 commits

Author SHA1 Message Date
Nate Bosch 113ff6c993 Enforce that allowInterop is used in DDC
Fixes #39074

DDC emits Dart code that can usually be called with the same semantics
as JS there is no guarantee that a function passed to JS and then
invoked successfully was wrapped with `allowInterop`. The wrapping is
always required in Dart2JS. To make DDC more strict, add interceptors
that check for the usage of `allowInterop`.

Whenever a JS interop function or setter is passed an argument which is
statically typed as a Function, but not wrapped with `allowInterop` at
the call site, wrap it with `assertInterop` which will check the
argument at call time and fail with a clear error if it was not wrapped.

Whenever a JS interop function is torn off, either at the top level or
from an instance, wrap it with a function that will also inject these
checks at runtime.

There are still holes where we can't catch the mistake:
- An argument which is statically dynamic and a Function at runtime
  won't be caught.
- A Function which is stored in a collection won't be caught.
- A JS interop definition where a getter returns a Function which takes
  a Function as an argument is not checked.
- A dynamic call through to javascript is not checked.

Changes:

- Refactor `_isJsLibrary` and add `isJsMember`, and `isAllowInterop`
  utilities to determine what needs wrapping.
- Update `assertInterop` to give a more clear error when it fails, and
  to ignore non function arguments.
- Add `tearoffInterop` to wrap a function an ensure that any function
  typed arguments are wrapped.
- Inject `assertInterop` around Function arguments passed to JS methods.
- Inject `assertInterop` around Function arguments passed to static or
  instance JS setters.
- Inject a runtime wrapper around static or instance Function tearoffs.
- Add a test covering all flavors of checks that are supported.
- Change the interop expando to an `Expando<dynamic>` in the NNBD SDK to work
  around a stricter type check. https://github.com/dart-lang/sdk/issues/39971

Potential improvements:

If the `tearoffInterop` turns out to be too heavy, we could loosen it so
that we only wrap methods if any of their argument types are statically
declared to be a Function.

Change-Id: Ibc92df5b54e1a041b4102a07b8398b774b6bd1d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128462
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Vijay Menon <vsm@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2020-01-02 20:24:26 +00:00
Konstantin Shcheglov df98317c42 Report unchecked nullable for explicit / implicit 'this' in extensions.
R=brianwilkerson@google.com

Bug: https://github.com/dart-lang/sdk/issues/39875
Change-Id: Ia0e5b9ea736428cd40d8898e48e0db605deebacd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130042
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-01-02 20:17:07 +00:00
Konstantin Shcheglov dbaeb9a6d9 Use NullableDereferenceVerifier in ErrorVerifier.
R=brianwilkerson@google.com

Change-Id: I0adc88b5e6874d2834f904da175757bdbd78772c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130009
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-01-02 19:45:24 +00:00
Konstantin Shcheglov d5c4099d1b Remove BUILT_IN_IDENTIFIER_AS_TYPE error code for 'addAsync' quick fix.
We report UNDEFINED_IDENTIFIER_AWAIT instead.

R=brianwilkerson@google.com

Change-Id: I9950e4a332b2a4f28232a36631f2f809d14068cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130008
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-02 19:44:09 +00:00
Alexander Markov ad12931304 [vm/compiler] Remove PushArguments from ThrowInstr, ReThrowInstr
Issue: https://github.com/dart-lang/sdk/issues/39788
Change-Id: Ic47d3b57a35182162848df61495f8963afd55fc6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129321
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-01-02 19:41:46 +00:00
Alexander Markov 2477378537 [vm/compiler] Refactor PolymorphicInstanceCallInstr
This change hides InstanceCallInstr inside PolymorphicInstanceCallInstr
and makes sure that PolymorphicInstanceCallInstr owns its arguments
(which would become critical once call arguments become instruction
inputs).

Also, PolymorphicInstanceCallInstr now extends TemplateDartCall which
makes it possible to avoid duplication of methods related to all calls.

Issue: https://github.com/dart-lang/sdk/issues/39788
Change-Id: Ie3d4ff46a8e99a0988ba88a88ca9a60be8503ce0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129307
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-01-02 19:09:36 +00:00
Konstantin Shcheglov ed4c692620 Remove ResolutionTest.assertErrorsWithCodes().
R=brianwilkerson@google.com

Change-Id: I2673465848ec9ce8f4a737f8c4291414f6809bd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130020
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-01-02 17:42:06 +00:00
Danny Tuppeny 7981947f75 Don't statically register LSP capabilities that will be dynamically registered
Fixes https://github.com/dart-lang/sdk/issues/39949.

Bug: https://github.com/dart-lang/sdk/issues/39949
Change-Id: I3a18ecfafae04d2a79841ead1481c8ad6c6cee83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129711
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-02 17:23:06 +00:00
Janice Collins 1fb5352943 Add --migrate-dependencies hidden option for dartfix.
Also makes option handling more agnostic to default
and negatable values, and disallows trying to use
the preview server outside of upgrade.

Change-Id: Icff10bd016d822edc9c37c0069ebc0c851f78a7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128920
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Janice Collins <jcollins@google.com>
Commit-Queue: Janice Collins <jcollins@google.com>
2020-01-02 17:21:26 +00:00
Danny Tuppeny 04146a36f0 Unskip LSP integration tests that were skipped for being flaky
These tests were previously quite slow due to running from source, but they now use the snapshot.

See https://github.com/dart-lang/sdk/issues/38629

Change-Id: Ief9df7d45b074a06c559b9eb66912f5e9b50cc8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129712
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2020-01-02 17:01:36 +00:00
pq a688de0371 Add deprecated member messages
Change-Id: I8efa2244b3f03a1af44eca93ed4441a255c6cb68
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129923
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-02 15:41:26 +00:00
Konstantin Shcheglov 8a4404e64b Remove assertTestErrorsWithCodes() and assertNoTestErrors().
R=brianwilkerson@google.com

Change-Id: Ia5e64bfe318a11a87ee24aafca94fad7c7c8beb0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130005
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-01-02 15:32:56 +00:00
Martin Kustermann 4e9a8c8e18 [vm/nnbd] First start on migrating VM patch files for NNBD
Issue https://github.com/dart-lang/sdk/issues/39754

Change-Id: Id0322ee6bde9b3af5483feacf73b590cdafbc62d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127160
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
2020-01-02 13:53:36 +00:00
Daco Harkes b8a679ab88 [vm] Fix IntConverter canonicalization
The check of not removing 64-bit->32-bit truncating conversions was in the wrong place.

Fixes: https://github.com/dart-lang/sdk/issues/39885
Fixes: https://github.com/flutter/flutter/issues/47454

Change-Id: Ic32a13cbf7ec622692cdca86b3237dae1c0f1cef
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129284
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-01-02 12:43:36 +00:00
Konstantin Shcheglov 2a208b2f7b Use ErrorReporter in TypeNameResolver.
R=brianwilkerson@google.com

Change-Id: I7985fbad36101480b292ebd0e06c0019b9856fbc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129961
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-02 07:14:36 +00:00
Konstantin Shcheglov 46fbc94985 Simplify 'void' resolution in TypeNameResolver.
Also, 'void' is a reserved word, and the grammar does not allow
type arguments after 'void':

<typeNotFunction> ::= void | <typeNotVoidNotFunction>

<typeNotVoidNotFunction> ::= <typeName> <typeArguments>? ... etc

R=brianwilkerson@google.com

Change-Id: Ia54916a8d30ac507bac2133dc3ffabd2c654b09b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129984
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-01-02 06:01:18 +00:00
Brian Wilkerson 8c6c27541e Disable a lint in the LSP generated code and re-run the generator
Turns out we aren't testing to ensure that the LSP generator has been
run as part of our test suite. Ideally we'd do so and we'd update the
generator to produce code that doesn't violate lints, but that's more
work than I can do today. Hence this stop-gap CL.

Change-Id: Ia9e5a35817fc4d08e2a4b87b9c2ef64725c822b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130004
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2020-01-02 04:55:46 +00:00
Brian Wilkerson c08cdb5a78 Enable avoid_return_types_on_setters in analysis_server_client
All changes (other than analysis_options.yaml and the change to the generator) made via dartfix.

Change-Id: I7b186371e22048ceddf6fd4407a66aba8b96480c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130003
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2020-01-02 04:55:38 +00:00
pq 6a8ab6a858 Remove unnecessary const modifiers
Change-Id: I2187b009abc150d8e361d00c673099ec7b4147f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129924
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
2020-01-02 00:48:55 +00:00
Konstantin Shcheglov c7f3020fc6 Extract error reporting from TypeNameResolver.
The extracted code mostly chooses which ErrorCode to report, and
does not do resolution logic itself. So, I think it will make the
resolver itself cleaner to keep it separately.

R=brianwilkerson@google.com

Change-Id: Idc6b652028ddb11913d5cd5c8273299ed94e7079
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129987
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-01 22:29:05 +00:00
Brian Wilkerson 91d6e1a0a7 Enable annotate_overrides in several packages
Other than analysis_server/test/analysis/notification_overrides_test.dart,
which had a naming conflict, all of the changes were made using dartfix.

Change-Id: I911dd75dcdee00420caa48724125e86d47c8857d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130002
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2020-01-01 21:31:40 +00:00
Brian Wilkerson d85f295496 Minor cleanup of DartFixInfo
Change-Id: I0a6d2b2fcac992471952fe3fcb7bfec1aea8d9c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130001
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2020-01-01 21:23:45 +00:00
Brian Wilkerson beb2ba31f7 Improve the fix for avoid_init_to_null to match the lint
Change-Id: Idc23dfebd96bb98125328e0297bfc3d81baa9775
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/130000
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2020-01-01 21:23:36 +00:00
Konstantin Shcheglov dce4de0b47 Deprecate assertNoTestErrors() and replace with assertNoErrorsInCode().
Change-Id: I3176e50d6cd86fa0863da5252ce52211a63f50b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129960
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-01-01 20:40:05 +00:00
Konstantin Shcheglov 99a39abe98 Stop using Identifier in several Scope.lookup() methods.
R=brianwilkerson@google.com, paulberry@google.com

Change-Id: I400f7c5b14f44fb1e2a8b3d5e52016dcc4924961
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129832
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-01-01 19:55:55 +00:00
Konstantin Shcheglov 850ca2d410 Add Element.getDisplayString(withNullability), use it in analyzer.
R=brianwilkerson@google.com

Change-Id: Ic4924e19612f2a7713f9a3f2059a880ebff9d2db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129983
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-01-01 19:01:14 +00:00
Konstantin Shcheglov 4a6cd94f61 Deprecate 'ErrorReporter.source' setter.
R=brianwilkerson@google.com

Change-Id: I6a0878f0abc206311299281919d41c8ef3b5fd3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129962
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-01-01 18:52:14 +00:00
Konstantin Shcheglov 7b7d8789ca Use WRONG_NUMBER_OF_TYPE_ARGUMENTS instead of two other equivalent error codes.
R=brianwilkerson@google.com

Change-Id: Ibb5ea7d65df75655eaf2d43fba1110740be39912
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129833
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-12-31 20:27:03 +00:00
Konstantin Shcheglov c941ad0cba Tweaks for DuplicateDefinitionVerifier.
Change-Id: I2e2ee36dd6061ae368da3c60a20866f40ab4ecec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129834
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-31 19:41:43 +00:00
Konstantin Shcheglov 13a05ee763 Simplify getNullability(hasQuestion).
R=brianwilkerson@google.com

Change-Id: I7c1f3eade62d10ff7eb854e27f10680d6a6af8da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129903
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-12-31 19:28:33 +00:00
Konstantin Shcheglov 73389e6af0 Remove almost all uses of assertTestErrorsWithCodes().
The only use is assertNoTestErrors(), it cannot be replaced with not
ExpectedError(s) at all, we have 209 tests failing with UNUSED_LOCAL_VARIABLE

R=brianwilkerson@google.com

Change-Id: I19b6e0785e7553c00b130f827b4bb35b0742507f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129831
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-31 19:19:03 +00:00
Konstantin Shcheglov 85bdbb37bd Update TypedLiteralResolver.computeElementType()
Slightly refactor, move Expression branches up, as first alphabetically.

R=brianwilkerson@google.com

Change-Id: I17afe6544c548a882396d83689233bfdd682935d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129835
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-31 19:10:23 +00:00
Konstantin Shcheglov 7cbc264231 TypeNameResolver refactoring - extract Element instantiation.
R=brianwilkerson@google.com

Change-Id: Icaaf2e988108b874fdc16dd837bf3d15eb82740e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129840
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-31 18:55:43 +00:00
Konstantin Shcheglov b169f35743 Remove unnecessary methods to record errors or tokens and nodes.
We used them for Proxy support, but it was removed since then.

R=brianwilkerson@google.com, devoncarew@google.com

Change-Id: I417e5f0a473fa4ce418f2e5be524c600e976b2e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129920
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-31 18:28:33 +00:00
Konstantin Shcheglov 4e38c9012a Remove 'isNonNullableByDefault' from TypeSystem.inferGenericFunctionOrType
R=brianwilkerson@google.com

Change-Id: Ibdca2d8c762d723ad5847ad99605618db19ad5f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129902
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-31 18:28:13 +00:00
Konstantin Shcheglov 9445dcc105 Use DartType.isDartCoreList in analysis_server.
R=brianwilkerson@google.com, devoncarew@google.com

Change-Id: I64cf52a06b08577215e7763f047f0cbea6390209
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129830
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-30 20:49:12 +00:00
William Hesse 05e70d5b38 [infra] Add unapproved failures test to builder status script
TBR: athom@google.com
Change-Id: I086b26acb310e407cb4060db1e14d7a7c6c57cdc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129707
Reviewed-by: William Hesse <whesse@google.com>
2019-12-30 14:02:23 +00:00
Zichang Guo d3b40e59c6 [vm/io] add endian.host to RawSocketOption.fromInt
This is the reland of 127489 with fix on Mac. IPv6 and IPv4 behave differently in setsockopt(). IPv6 requires an index instead of an address.
https://dart-review.googlesource.com/c/sdk/+/127489

Bug: https://github.com/dart-lang/sdk/issues/39691
Change-Id: Idc0449e88be47663851f2de90cdbbf3f13466221
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128367
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Zichang Guo <zichangguo@google.com>
2019-12-30 09:34:18 +00:00
Sam Rawlins f1084cdf0b analyzer: move tests for 10 error codes to separate files
Change-Id: I708b0ae276d7da7247d10b854eeedc52fb69e68e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129829
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-12-30 04:31:08 +00:00
Sam Rawlins 566f173f0c analyzer: Fix duplicate error-reporting with duplicate field formals
Change-Id: I80e158b33e7ea6ae4769b37f1a3448ebf6e061a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129824
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-12-30 04:29:18 +00:00
Sam Rawlins 282dcb6f44 analyzer: move 'non-error' tests for 12 codes to separate files
Change-Id: I30e8442f48afd018467239d6c9d966d25c087284
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129704
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2019-12-30 03:40:38 +00:00
Konstantin Shcheglov 0c7048be74 Remove reporting duplicate CompileTimeErrorCode.CONST_NOT_INITIALIZED from ConstructorFieldsVerifier.
R=brianwilkerson@google.com

Change-Id: I1566c0d4f955846671823fd3736f71f08281d5c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129705
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-12-30 01:24:38 +00:00
Devon Carew 37b78b601d [analyzer] improve the cursor insertion position for required params
Change-Id: I28f3d4677de34d3dc6e28e9e71d73b99c895615c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129825
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2019-12-30 01:09:48 +00:00
Konstantin Shcheglov c0819e7b81 Simplify SyntheticIdentifier to partial SimpleIdentifier.
R=brianwilkerson@google.com, paulberry@google.com

Change-Id: I554df4fcf887497173b4fd29a26f28f47d7f0ab9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129828
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-30 00:53:18 +00:00
Konstantin Shcheglov 90c5eb0603 Remove 'referencingLibrary' from several Scope.lookupX() methods.
We don't use them, instead corresponding import namespaces don't
include private declarations.

R=brianwilkerson@google.com, paulberry@google.com

Change-Id: I727ed92a643412a90f691c6966efb90121b079d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129827
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-30 00:48:18 +00:00
Konstantin Shcheglov 45b780e04c Add canReferenceElementWithoutThisPrefix() to LinterContext.
With this approach, UnnecessaryThis is a bit more complicated than
the one outlined in the previous message:

  @override
  void visitThisExpression(ThisExpression node) {
    final parent = node.parent;

    Element element;
    if (parent is PropertyAccess) {
      element = parent.propertyName.staticElement;
    } else if (parent is MethodInvocation) {
      element = parent.methodName.staticElement;
    } else {
      return;
    }

    if (_canReferenceElementWithoutThisPrefix(element, node)) {
      rule.reportLint(parent);
    }
  }

  bool _canReferenceElementWithoutThisPrefix(Element element, AstNode node) {
    if (element == null) {
      return false;
    }

    var id = element.displayName;
    var isSetter = element is PropertyAccessorElement && element.isSetter;
    var result = context.resolveNameInScope(id, isSetter, node);

    // No result, definitely no shadowing.
    // The requested element is inherited, or from an extension.
    if (result.isNone) {
      return true;
    }

    // The result has the matching name, might be shadowing.
    // Check that the element is the same.
    if (result.isRequestedName) {
      return result.element == element;
    }

    // The result has the same basename, but not the same name.
    // Must be an instance member, so that:
    //  - not shadowed by a local declaration;
    //  - prevents us from going up to the library scope;
    //  - the requested element must be inherited, or from an extension.
    if (result.isDifferentName) {
      var enclosing = result.element.enclosingElement;
      return enclosing is ClassElement;
    }

    // Should not happen.
    return false;
  }

R=brianwilkerson@google.com, pquitslund@google.com

Change-Id: I83e2a3a67f3db43caeb8157116e823268c9bfec7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129819
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-29 22:31:37 +00:00
Devon Carew 11b66df561 [analyzer] fix an issue with the missing_required_param warning ending in two periods
Change-Id: Ie4ac2893c763c7b61e698ee6b95b39ad6cd4243a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129826
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2019-12-29 20:42:07 +00:00
Brian Wilkerson 4264c5ebd8 Add a fix for prefer_if_null_operators
Change-Id: I5290016b069d3e31f7b370dbc85d1a6ed65b57f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129822
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2019-12-29 17:31:47 +00:00
Devon Carew 28a1067b25 [analyzer] insert missing params before child/children
Change-Id: Ic2c19ebcb8e4c6a7d89c2c1317c18ebd00bc6e96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129823
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2019-12-29 04:05:16 +00:00
Paul Berry 1317212b22 Migration: teach FixBuilder to add the required keyword when necessary.
Change-Id: Ifb20e60f1ea8578bcdcfe503582902734d56b881
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129326
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2019-12-28 23:50:56 +00:00