Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: pkg/compiler/lib/src/typechecker.dart

Issue 1151163004: Implementation of null-aware operators. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/tree/unparser.dart ('k') | pkg/compiler/lib/src/universe/universe.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/typechecker.dart
diff --git a/pkg/compiler/lib/src/typechecker.dart b/pkg/compiler/lib/src/typechecker.dart
index 8cf2b8042a3916da63b915fc3022f1112f7e83e2..7e29871d4c4a9ac3eea579b7aac2dbc1d172b8e5 100644
--- a/pkg/compiler/lib/src/typechecker.dart
+++ b/pkg/compiler/lib/src/typechecker.dart
@@ -1237,6 +1237,10 @@ class TypeCheckerVisitor extends Visitor<DartType> {
return boolType;
} else if (identical(name, '?')) {
return boolType;
+ } else if (identical(name, '??')) {
+ final Node argument = node.arguments.head;
+ final DartType argumentType = analyze(argument);
+ return types.computeLeastUpperBound(receiverType, argumentType);
}
String operatorName = selector.source;
if (identical(name, '-') && node.arguments.isEmpty) {
@@ -1405,7 +1409,7 @@ class TypeCheckerVisitor extends Visitor<DartType> {
Element element = elements[node];
Identifier selector = node.selector;
final name = node.assignmentOperator.source;
- if (identical(name, '=')) {
+ if (identical(name, '=') || identical(name, '??=')) {
// e1 = value
if (node.isIndex) {
// base[key] = value
@@ -1416,14 +1420,16 @@ class TypeCheckerVisitor extends Visitor<DartType> {
final DartType value = analyze(valueNode);
DartType indexSet = lookupMemberType(
node, base, '[]=', MemberKind.OPERATOR);
+ DartType indexSetValue = const DynamicType();
if (indexSet is FunctionType) {
FunctionType indexSetType = indexSet;
DartType indexSetKey = firstType(indexSetType.parameterTypes);
checkAssignable(keyNode, key, indexSetKey);
- DartType indexSetValue = secondType(indexSetType.parameterTypes);
+ indexSetValue = secondType(indexSetType.parameterTypes);
checkAssignable(node.assignmentOperator, value, indexSetValue);
}
- return value;
+ return identical(name, '=') ? value
+ : types.computeLeastUpperBound(value, indexSetValue);
} else {
// target = value
DartType target;
@@ -1441,7 +1447,8 @@ class TypeCheckerVisitor extends Visitor<DartType> {
final Node valueNode = node.arguments.head;
final DartType value = analyze(valueNode);
checkAssignable(node.assignmentOperator, value, target);
- return value;
+ return identical(name, '=') ? value
+ : types.computeLeastUpperBound(value, target);
}
} else if (identical(name, '++') || identical(name, '--')) {
// e++ or e--
« no previous file with comments | « pkg/compiler/lib/src/tree/unparser.dart ('k') | pkg/compiler/lib/src/universe/universe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698