Skip to content

Commit

Permalink
[cfe] Add test for covariant late final fields
Browse files Browse the repository at this point in the history
Closes flutter#40805

Change-Id: I896bce935803a951cfb8c9c0d0f70a6227de2413
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139464
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
  • Loading branch information
johnniwinther authored and commit-bot@chromium.org committed Mar 16, 2020
1 parent e470662 commit d295073
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/front_end/testcases/late_lowering/issue40805.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// 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.

main() {
D().x = 3.14;
}

class C {
covariant late final int x;
}

class D extends C {
set x(num value) { super.x = value.toInt(); }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

class C extends core::Object {
covariant field core::int? _#C#x;
synthetic constructor •() → self::C
;
get x() → core::int;
set x(core::int #t1) → void;
}
class D extends self::C {
synthetic constructor •() → self::D
;
set x(core::num value) → void
;
}
static method main() → dynamic
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
import "dart:_internal" as _in;

class C extends core::Object {
covariant field core::int? _#C#x = null;
synthetic constructor •() → self::C
: super core::Object::•()
;
get x() → core::int
return let final core::int? #t1 = this.{self::C::_#C#x} in #t1.==(null) ?{core::int} throw new _in::LateInitializationErrorImpl::•("Field 'x' has not been initialized.") : #t1{core::int};
set x(core::int #t2) → void
if(this.{self::C::_#C#x}.==(null))
this.{self::C::_#C#x} = #t2;
else
throw new _in::LateInitializationErrorImpl::•("Field 'x' has already been initialized.");
}
class D extends self::C {
synthetic constructor •() → self::D
: super self::C::•()
;
set x(core::num value) → void {
super.{self::C::x} = value.{core::num::toInt}();
}
}
static method main() → dynamic {
new self::D::•().{self::D::x} = 3.14;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
import "dart:_internal" as _in;

class C extends core::Object {
covariant field core::int? _#C#x = null;
synthetic constructor •() → self::C
: super core::Object::•()
;
get x() → core::int
return let final core::int? #t1 = this.{self::C::_#C#x} in #t1.==(null) ?{core::int} throw new _in::LateInitializationErrorImpl::•("Field 'x' has not been initialized.") : #t1{core::int};
set x(core::int #t2) → void
if(this.{self::C::_#C#x}.==(null))
this.{self::C::_#C#x} = #t2;
else
throw new _in::LateInitializationErrorImpl::•("Field 'x' has already been initialized.");
}
class D extends self::C {
synthetic constructor •() → self::D
: super self::C::•()
;
set x(core::num value) → void {
super.{self::C::x} = value.{core::num::toInt}();
}
}
static method main() → dynamic {
new self::D::•().{self::D::x} = 3.14;
}
29 changes: 29 additions & 0 deletions pkg/front_end/testcases/late_lowering/issue40805.dart.weak.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
import "dart:_internal" as _in;

class C extends core::Object {
covariant field core::int? _#C#x = null;
synthetic constructor •() → self::C
: super core::Object::•()
;
get x() → core::int
return let final core::int? #t1 = this.{self::C::_#C#x} in #t1.==(null) ?{core::int} throw new _in::LateInitializationErrorImpl::•("Field 'x' has not been initialized.") : #t1{core::int};
set x(core::int #t2) → void
if(this.{self::C::_#C#x}.==(null))
this.{self::C::_#C#x} = #t2;
else
throw new _in::LateInitializationErrorImpl::•("Field 'x' has already been initialized.");
}
class D extends self::C {
synthetic constructor •() → self::D
: super self::C::•()
;
set x(core::num value) → void {
super.{self::C::x} = value.{core::num::toInt}();
}
}
static method main() → dynamic {
new self::D::•().{self::D::x} = 3.14;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;
import "dart:_internal" as _in;

class C extends core::Object {
covariant field core::int? _#C#x = null;
synthetic constructor •() → self::C
: super core::Object::•()
;
get x() → core::int
return let final core::int? #t1 = this.{self::C::_#C#x} in #t1.==(null) ?{core::int} throw new _in::LateInitializationErrorImpl::•("Field 'x' has not been initialized.") : #t1{core::int};
set x(core::int #t2) → void
if(this.{self::C::_#C#x}.==(null))
this.{self::C::_#C#x} = #t2;
else
throw new _in::LateInitializationErrorImpl::•("Field 'x' has already been initialized.");
}
class D extends self::C {
synthetic constructor •() → self::D
: super self::C::•()
;
set x(core::num value) → void {
super.{self::C::x} = value.{core::num::toInt}();
}
}
static method main() → dynamic {
new self::D::•().{self::D::x} = 3.14;
}
15 changes: 15 additions & 0 deletions pkg/front_end/testcases/nnbd/issue40805.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// 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.

main() {
D().x = 3.14;
}

class C {
covariant late final int x;
}

class D extends C {
set x(num value) { super.x = value.toInt(); }
}
17 changes: 17 additions & 0 deletions pkg/front_end/testcases/nnbd/issue40805.dart.outline.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

class C extends core::Object {
late covariant final [setter] field core::int x;
synthetic constructor •() → self::C
;
}
class D extends self::C {
synthetic constructor •() → self::D
;
set x(covariant core::num value) → void
;
}
static method main() → dynamic
;
21 changes: 21 additions & 0 deletions pkg/front_end/testcases/nnbd/issue40805.dart.strong.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

class C extends core::Object {
late covariant final [setter] field core::int x;
synthetic constructor •() → self::C
: super core::Object::•()
;
}
class D extends self::C {
synthetic constructor •() → self::D
: super self::C::•()
;
set x(covariant core::num value) → void {
super.{self::C::x} = value.{core::num::toInt}();
}
}
static method main() → dynamic {
new self::D::•().{self::D::x} = 3.14;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

class C extends core::Object {
late covariant final [setter] field core::int x;
synthetic constructor •() → self::C
: super core::Object::•()
;
}
class D extends self::C {
synthetic constructor •() → self::D
: super self::C::•()
;
set x(covariant core::num value) → void {
super.{self::C::x} = value.{core::num::toInt}();
}
}
static method main() → dynamic {
new self::D::•().{self::D::x} = 3.14;
}
21 changes: 21 additions & 0 deletions pkg/front_end/testcases/nnbd/issue40805.dart.weak.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

class C extends core::Object {
late covariant final [setter] field core::int x;
synthetic constructor •() → self::C
: super core::Object::•()
;
}
class D extends self::C {
synthetic constructor •() → self::D
: super self::C::•()
;
set x(covariant core::num value) → void {
super.{self::C::x} = value.{core::num::toInt}();
}
}
static method main() → dynamic {
new self::D::•().{self::D::x} = 3.14;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

class C extends core::Object {
late covariant final [setter] field core::int x;
synthetic constructor •() → self::C
: super core::Object::•()
;
}
class D extends self::C {
synthetic constructor •() → self::D
: super self::C::•()
;
set x(covariant core::num value) → void {
super.{self::C::x} = value.{core::num::toInt}();
}
}
static method main() → dynamic {
new self::D::•().{self::D::x} = 3.14;
}
2 changes: 2 additions & 0 deletions pkg/front_end/testcases/text_serialization.status
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ late_lowering/instance_nullable_final_field_without_initializer: TextSerializati
late_lowering/issue40093: TextSerializationFailure
late_lowering/issue40373: TextSerializationFailure
late_lowering/issue40373b: TextSerializationFailure
late_lowering/issue40805: TextSerializationFailure
late_lowering/late_field_inference: TextSerializationFailure
late_lowering/late_field_with_initializer: TextSerializationFailure
late_lowering/late_field_without_initializer: TextSerializationFailure
Expand Down Expand Up @@ -1277,6 +1278,7 @@ nnbd/issue40093: TextSerializationFailure
nnbd/issue40134: TextSerializationFailure
nnbd/issue40512/issue40512: TextSerializationFailure
nnbd/issue40600: TextSerializationFailure
nnbd/issue40805: TextSerializationFailure
nnbd/issue_39286: TextSerializationFailure
nnbd/issue_39286_2: TextSerializationFailure
nnbd/late: TextSerializationFailure
Expand Down

0 comments on commit d295073

Please sign in to comment.