Skip to content

Commit 7418238

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Implement LibraryElementForLink.session and return (empty) AnalysisSessionForLink.
[email protected], [email protected] Bug: https://buganizer.corp.google.com/issues/127956822 Change-Id: Ifc93882d9ae7ae6079497fb10f3feea7ac6fb9e2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96864 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 806ec11 commit 7418238

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

pkg/analyzer/lib/src/summary/link.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/dart/analysis/session.dart';
6-
75
/// This library is capable of producing linked summaries from unlinked
86
/// ones (or prelinked ones). It functions by building a miniature
97
/// element model to represent the contents of the summaries, and then
@@ -57,6 +55,7 @@ import 'package:analyzer/dart/analysis/session.dart';
5755
///
5856
/// - Where possible, we favor method dispatch instead of "is" and "as"
5957
/// checks. E.g. see [ReferenceableElementForLink.asConstructor].
58+
import 'package:analyzer/dart/analysis/session.dart';
6059
import 'package:analyzer/dart/ast/ast.dart';
6160
import 'package:analyzer/dart/ast/standard_ast_factory.dart';
6261
import 'package:analyzer/dart/element/element.dart';
@@ -413,6 +412,11 @@ typedef LinkedLibrary GetDependencyCallback(String absoluteUri);
413412
/// [UnlinkedUnit] objects.
414413
typedef UnlinkedUnit GetUnitCallback(String absoluteUri);
415414

415+
class AnalysisSessionForLink implements AnalysisSession {
416+
@override
417+
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
418+
}
419+
416420
/// Element representing a class or enum resynthesized from a summary
417421
/// during linking.
418422
abstract class ClassElementForLink
@@ -3638,6 +3642,9 @@ abstract class LibraryElementForLink<
36383642
@override
36393643
LibraryResynthesizerContext get resynthesizerContext => this;
36403644

3645+
@override
3646+
AnalysisSession get session => _linker.session;
3647+
36413648
@override
36423649
Source get source => definingCompilationUnit.source;
36433650

@@ -3936,6 +3943,7 @@ class Linker {
39363943
SpecialTypeElementForLink _bottomElement;
39373944
InheritanceManager2 _inheritanceManager;
39383945
ContextForLink _context;
3946+
AnalysisSessionForLink _session;
39393947

39403948
/// Gets an instance of [AnalysisOptions] for use during linking.
39413949
final AnalysisOptions analysisOptions;
@@ -3976,6 +3984,10 @@ class Linker {
39763984
InheritanceManager2 get inheritanceManager =>
39773985
_inheritanceManager ??= new InheritanceManager2(typeSystem);
39783986

3987+
/// Get a stub implementation of [AnalysisContext] which can be used during
3988+
/// linking.
3989+
get session => _session ??= new AnalysisSessionForLink();
3990+
39793991
/// Indicates whether type inference should use strong mode rules.
39803992
@deprecated
39813993
bool get strongMode => true;

pkg/analyzer/lib/src/summary2/ast_binary_writer.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,11 +1009,16 @@ class AstBinaryWriter extends ThrowingAstVisitor<LinkedNodeBuilder> {
10091009

10101010
@override
10111011
LinkedNodeBuilder visitSimpleIdentifier(SimpleIdentifier node) {
1012-
var isDeclared = node.inDeclarationContext();
1012+
Element element;
1013+
if (!node.inDeclarationContext()) {
1014+
element = node.staticElement;
1015+
if (element is MultiplyDefinedElement) {
1016+
element = null;
1017+
}
1018+
}
10131019

10141020
return LinkedNodeBuilder.simpleIdentifier(
1015-
simpleIdentifier_element:
1016-
isDeclared ? null : _getReferenceIndex(node.staticElement),
1021+
simpleIdentifier_element: _getReferenceIndex(element),
10171022
simpleIdentifier_token: _getToken(node.token),
10181023
expression_type: _writeType(node.staticType),
10191024
);

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7800,6 +7800,21 @@ int y;
78007800
''');
78017801
}
78027802

7803+
test_type_inference_multiplyDefinedElement() async {
7804+
addLibrarySource('/a.dart', 'class C {}');
7805+
addLibrarySource('/b.dart', 'class C {}');
7806+
var library = await checkLibrary('''
7807+
import 'a.dart';
7808+
import 'b.dart';
7809+
var v = C;
7810+
''');
7811+
checkElementText(library, r'''
7812+
import 'a.dart';
7813+
import 'b.dart';
7814+
dynamic v;
7815+
''');
7816+
}
7817+
78037818
test_type_inference_nested_function() async {
78047819
var library = await checkLibrary('''
78057820
var x = (t) => (u) => t + u;

0 commit comments

Comments
 (0)