Skip to content

Commit

Permalink
Implement LibraryElementForLink.session and return (empty) AnalysisSe…
Browse files Browse the repository at this point in the history
…ssionForLink.

[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]>
  • Loading branch information
scheglov authored and [email protected] committed Mar 14, 2019
1 parent 806ec11 commit 7418238
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
16 changes: 14 additions & 2 deletions pkg/analyzer/lib/src/summary/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/analysis/session.dart';

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

class AnalysisSessionForLink implements AnalysisSession {
@override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

/// Element representing a class or enum resynthesized from a summary
/// during linking.
abstract class ClassElementForLink
Expand Down Expand Up @@ -3638,6 +3642,9 @@ abstract class LibraryElementForLink<
@override
LibraryResynthesizerContext get resynthesizerContext => this;

@override
AnalysisSession get session => _linker.session;

@override
Source get source => definingCompilationUnit.source;

Expand Down Expand Up @@ -3936,6 +3943,7 @@ class Linker {
SpecialTypeElementForLink _bottomElement;
InheritanceManager2 _inheritanceManager;
ContextForLink _context;
AnalysisSessionForLink _session;

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

/// Get a stub implementation of [AnalysisContext] which can be used during
/// linking.
get session => _session ??= new AnalysisSessionForLink();

/// Indicates whether type inference should use strong mode rules.
@deprecated
bool get strongMode => true;
Expand Down
11 changes: 8 additions & 3 deletions pkg/analyzer/lib/src/summary2/ast_binary_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1009,11 +1009,16 @@ class AstBinaryWriter extends ThrowingAstVisitor<LinkedNodeBuilder> {

@override
LinkedNodeBuilder visitSimpleIdentifier(SimpleIdentifier node) {
var isDeclared = node.inDeclarationContext();
Element element;
if (!node.inDeclarationContext()) {
element = node.staticElement;
if (element is MultiplyDefinedElement) {
element = null;
}
}

return LinkedNodeBuilder.simpleIdentifier(
simpleIdentifier_element:
isDeclared ? null : _getReferenceIndex(node.staticElement),
simpleIdentifier_element: _getReferenceIndex(element),
simpleIdentifier_token: _getToken(node.token),
expression_type: _writeType(node.staticType),
);
Expand Down
15 changes: 15 additions & 0 deletions pkg/analyzer/test/src/summary/resynthesize_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7800,6 +7800,21 @@ int y;
''');
}

test_type_inference_multiplyDefinedElement() async {
addLibrarySource('/a.dart', 'class C {}');
addLibrarySource('/b.dart', 'class C {}');
var library = await checkLibrary('''
import 'a.dart';
import 'b.dart';
var v = C;
''');
checkElementText(library, r'''
import 'a.dart';
import 'b.dart';
dynamic v;
''');
}

test_type_inference_nested_function() async {
var library = await checkLibrary('''
var x = (t) => (u) => t + u;
Expand Down

0 comments on commit 7418238

Please sign in to comment.