Skip to content

Commit ea4afe3

Browse files
liamappelbeCommit Queue
authored andcommitted
[analyzer] Fix const analysis for FFI callback exceptional returns
Bug: https://buganizer.corp.google.com/issues/443858706 Change-Id: I283efa11402c0c3e1930f46abb45aed2b3c3d543 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449100 Reviewed-by: Ivan Inozemtsev <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Liam Appelbe <[email protected]>
1 parent 17279c9 commit ea4afe3

File tree

2 files changed

+4
-27
lines changed

2 files changed

+4
-27
lines changed

pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,6 @@ class LibraryAnalyzer {
486486
FfiVerifier(
487487
_typeSystem,
488488
diagnosticReporter,
489-
_libraryElement,
490-
_declaredVariables,
491489
strictCasts: _analysisOptions.strictCasts,
492490
),
493491
);

pkg/analyzer/lib/src/generated/ffi_verifier.dart

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +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/declared_variables.dart';
65
import 'package:analyzer/dart/ast/syntactic_entity.dart';
76
import 'package:analyzer/dart/ast/token.dart';
87
import 'package:analyzer/dart/ast/visitor.dart';
@@ -13,8 +12,6 @@ import 'package:analyzer/dart/element/type.dart';
1312
import 'package:analyzer/error/listener.dart';
1413
import 'package:analyzer/src/dart/ast/ast.dart';
1514
import 'package:analyzer/src/dart/ast/extensions.dart';
16-
import 'package:analyzer/src/dart/constant/evaluation.dart';
17-
import 'package:analyzer/src/dart/constant/value.dart';
1815
import 'package:analyzer/src/dart/element/element.dart';
1916
import 'package:analyzer/src/dart/element/type.dart';
2017
import 'package:analyzer/src/dart/element/type_system.dart';
@@ -109,24 +106,15 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
109106
/// Subclass of `Struct` or `Union` we are currently visiting, or `null`.
110107
ClassDeclaration? compound;
111108

112-
final LibraryElementImpl _currentLibrary;
113-
114-
final ConstantEvaluationEngine _evaluationEngine;
115-
116109
/// The `Void` type from `dart:ffi`, or `null` if unresolved.
117110
InterfaceTypeImpl? ffiVoidType;
118111

119112
/// Initialize a newly created verifier.
120113
FfiVerifier(
121114
this.typeSystem,
122-
this._diagnosticReporter,
123-
this._currentLibrary,
124-
DeclaredVariables declaredVariables, {
115+
this._diagnosticReporter, {
125116
required this.strictCasts,
126-
}) : _evaluationEngine = ConstantEvaluationEngine(
127-
declaredVariables: declaredVariables,
128-
configuration: ConstantEvaluationConfiguration(),
129-
);
117+
});
130118

131119
@override
132120
void visitClassDeclaration(covariant ClassDeclarationImpl node) {
@@ -756,17 +744,8 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
756744
}
757745

758746
bool _isConst(Expression expr) {
759-
var subDiagnosticReporter = DiagnosticReporter(
760-
RecordingDiagnosticListener(),
761-
_diagnosticReporter.source,
762-
);
763-
var constantVisitor = ConstantVisitor(
764-
_evaluationEngine,
765-
_currentLibrary,
766-
subDiagnosticReporter,
767-
);
768-
var result = constantVisitor.evaluateConstant(expr);
769-
return result is! InvalidConstant;
747+
var computedConstant = expr.computeConstantValue();
748+
return computedConstant?.value != null;
770749
}
771750

772751
bool _isLeaf(NodeList<Expression>? args) {

0 commit comments

Comments
 (0)