Const evaluation for int2double
Change-Id: I4673ab47d9dfcb8de62a5190a6dd2b9c79ef1d19
Reviewed-on: https://dart-review.googlesource.com/74496
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index d4eb48a..64ad7bf 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -879,6 +879,11 @@
if (type.isUndefined) {
return false;
}
+ // TODO(mfairhurst): Remove this once #33441 is solved and we can use
+ // inference properly. This is a hack.
+ if (obj.type == typeProvider.intType && type == typeProvider.doubleType) {
+ return true;
+ }
return obj.type.isSubtypeOf(type);
}
diff --git a/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_test.dart b/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_test.dart
index 0a5de28..1d53be6 100644
--- a/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_test.dart
+++ b/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_test.dart
@@ -650,7 +650,7 @@
class D extends C {
const D(d) : super(d);
}
-const f = const D(0);
+const f = const D('0.0');
''');
await computeAnalysisResult(source);
assertErrors(
diff --git a/pkg/analyzer/test/generated/non_error_resolver_test.dart b/pkg/analyzer/test/generated/non_error_resolver_test.dart
index a4a56f1..f411b0f 100644
--- a/pkg/analyzer/test/generated/non_error_resolver_test.dart
+++ b/pkg/analyzer/test/generated/non_error_resolver_test.dart
@@ -2861,6 +2861,52 @@
verify([source]);
}
+ test_intLiteralInDoubleContext_const() async {
+ Source source = addSource(r'''
+class C {
+ const C(double x)
+ : assert((x + 3) / 2 == 1.5)
+ , assert(x == 0.0);
+}
+@C(0)
+@C(-0)
+@C(0x0)
+@C(-0x0)
+void main() {
+ const C(0);
+ const C(-0);
+ const C(0x0);
+ const C(-0x0);
+}''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
+ @failingTest
+ test_intLiteralInDoubleContext_const_exact() async {
+ // TODO(mfairhurst): get the commented out assertions to pass.
+ Source source = addSource(r'''
+class C {
+ const C(double x)
+ : assert("$x" == "0.0")
+ , assert(identical(x, 0.0));
+}
+@C(0)
+@C(-0)
+@C(0x0)
+@C(-0x0)
+void main() {
+ const C(0);
+ const C(-0);
+ const C(0x0);
+ const C(-0x0);
+}''');
+ await computeAnalysisResult(source);
+ assertNoErrors(source);
+ verify([source]);
+ }
+
test_invalidAnnotation_constantVariable_field() async {
Source source = addSource(r'''
@A.C
diff --git a/tests/co19_2/co19_2-analyzer.status b/tests/co19_2/co19_2-analyzer.status
index 888b54a..56a4a12 100644
--- a/tests/co19_2/co19_2-analyzer.status
+++ b/tests/co19_2/co19_2-analyzer.status
@@ -225,11 +225,5 @@
LanguageFeatures/Super-bounded-types/static_analysis_A01_t07: CompileTimeError # Issue 32903
LanguageFeatures/Super-bounded-types/static_analysis_A01_t08: CompileTimeError # Issue 32903
LanguageFeatures/Super-bounded-types/static_analysis_A01_t09: CompileTimeError # Issue 32903
-LanguageFeatures/int-to-double/assignment_class_member_t01: CompileTimeError # Has const, not working
-LanguageFeatures/int-to-double/assignment_class_member_t02: CompileTimeError # Has const, not working
-LanguageFeatures/int-to-double/assignment_global_variable_t01: CompileTimeError # Has const, not working
-LanguageFeatures/int-to-double/assignment_global_variable_t02: CompileTimeError # Has const, not working
-LanguageFeatures/int-to-double/assignment_local_variable_t01: CompileTimeError # Has const, not working
-LanguageFeatures/int-to-double/assignment_local_variable_t02: CompileTimeError # Has const, not working
LanguageFeatures/int-to-double/min_acceptable_values_t01: CompileTimeError # https://github.com/dart-lang/co19/issues/161
LanguageFeatures/int-to-double/representation_t01: CompileTimeError # https://github.com/dart-lang/co19/issues/160
diff --git a/tests/language_2/language_2.status b/tests/language_2/language_2.status
index 5cc4efa..95f2fc6 100644
--- a/tests/language_2/language_2.status
+++ b/tests/language_2/language_2.status
@@ -13,7 +13,7 @@
mixin_constructor_forwarding/optional_positional_parameters_test/none: CompileTimeError # Issue 31543
[ $compiler == dart2analyzer ]
-double_literals/implicit_double_context_test: CompileTimeError # const not yet supported
+double_literals/implicit_double_context_test: CompileTimeError # Needs triage, see Issue #34444
[ $compiler != dart2analyzer ]
switch_case_warn_test: Skip # Analyzer only, see language_analyzer2.status
diff --git a/tests/language_2/language_2_analyzer.status b/tests/language_2/language_2_analyzer.status
index 6251d21..299bdcd 100644
--- a/tests/language_2/language_2_analyzer.status
+++ b/tests/language_2/language_2_analyzer.status
@@ -19,6 +19,9 @@
conflicting_generic_interfaces_hierarchy_loop_infinite_test: Skip # Issue #34333 (loops forever)
const_cast2_test/01: CompileTimeError # failing-by-design: Not a const expression, see Issue #34334
const_cast2_test/none: CompileTimeError # failing-by-design: Not a const expression, see Issue #34334
+const_constructor3_test/02: MissingCompileTimeError # Needs triage, see Issue #34443
+const_constructor3_test/04: MissingCompileTimeError # Side-effect of working around issue 33441 for int-to-double
+const_init2_test/02: MissingCompileTimeError # Needs triage, see Issue #34443
constructor_reference_test/27: MissingCompileTimeError # Issue 34403
covariant_subtyping_with_mixin_test: CompileTimeError # Issue 34329
default_implementation2_test: CompileTimeError # Issue #34338, however, needs triage (#34337) and blocked (#34336)
diff --git a/tests/language_2/language_2_dartdevc.status b/tests/language_2/language_2_dartdevc.status
index 0938907..4c23494 100644
--- a/tests/language_2/language_2_dartdevc.status
+++ b/tests/language_2/language_2_dartdevc.status
@@ -32,8 +32,11 @@
conflicting_generic_interfaces_simple_test: MissingCompileTimeError
const_cast2_test/01: CompileTimeError
const_cast2_test/none: CompileTimeError
+const_constructor3_test/02: MissingCompileTimeError # Needs triage, see Issue #34443
+const_constructor3_test/04: MissingCompileTimeError # Side-effect of working around issue 33441 for int-to-double
const_constructor_mixin3_test/01: MissingCompileTimeError # Issue 33644
const_constructor_mixin_test/01: MissingCompileTimeError # Issue 33644
+const_init2_test/02: MissingCompileTimeError # Needs triage, see Issue #34443
constructor_reference_test/27: MissingCompileTimeError # Issue https://github.com/dart-lang/sdk/issues/34403
covariance_field_test/03: RuntimeError
covariant_override/tear_off_type_test: RuntimeError # Issue 28395