-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cfe] Handle extension setters on nullable types
Change-Id: I5b36246038f0c7b94c9d317c2273e00ab8e8772e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152500 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Dmitry Stefantsov <[email protected]>
- Loading branch information
1 parent
45af991
commit 233fe72
Showing
8 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2019, 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. | ||
|
||
class C { | ||
String m = ""; | ||
void set setter(String v) {} | ||
void operator []=(int index, String value) {} | ||
} | ||
|
||
extension on C? { | ||
void set setter(String v) { | ||
this?.m = v; | ||
} | ||
|
||
void operator []=(int index, String value) { | ||
this?.m = '$index$value'; | ||
} | ||
} | ||
|
||
main() { | ||
C? c = new C(); | ||
expect("", c?.m); | ||
c.setter = "42"; | ||
expect("42", c?.m); | ||
c[42] = "87"; | ||
expect("4287", c?.m); | ||
} | ||
|
||
expect(expected, actual) { | ||
if (expected != actual) throw 'Expected $expected, actual $actual'; | ||
} |
25 changes: 25 additions & 0 deletions
25
pkg/front_end/testcases/nnbd/nullable_setter.dart.outline.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
class C extends core::Object { | ||
field core::String m; | ||
synthetic constructor •() → self::C | ||
; | ||
set setter(core::String v) → void | ||
; | ||
operator []=(core::int index, core::String value) → void | ||
; | ||
} | ||
extension _extension#0 on self::C? { | ||
operator []= = self::_extension#0|[]=; | ||
set setter = self::_extension#0|set#setter; | ||
} | ||
static method _extension#0|set#setter(final self::C? #this, core::String v) → void | ||
; | ||
static method _extension#0|[]=(final self::C? #this, core::int index, core::String value) → void | ||
; | ||
static method main() → dynamic | ||
; | ||
static method expect(dynamic expected, dynamic actual) → dynamic | ||
; |
34 changes: 34 additions & 0 deletions
34
pkg/front_end/testcases/nnbd/nullable_setter.dart.strong.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
class C extends core::Object { | ||
field core::String m = ""; | ||
synthetic constructor •() → self::C | ||
: super core::Object::•() | ||
; | ||
set setter(core::String v) → void {} | ||
operator []=(core::int index, core::String value) → void {} | ||
} | ||
extension _extension#0 on self::C? { | ||
operator []= = self::_extension#0|[]=; | ||
set setter = self::_extension#0|set#setter; | ||
} | ||
static method _extension#0|set#setter(final self::C? #this, core::String v) → void { | ||
let final self::C? #t1 = #this in #t1.{core::Object::==}(null) ?{core::String?} null : #t1{self::C}.{self::C::m} = v; | ||
} | ||
static method _extension#0|[]=(final self::C? #this, core::int index, core::String value) → void { | ||
let final self::C? #t2 = #this in #t2.{core::Object::==}(null) ?{core::String?} null : #t2{self::C}.{self::C::m} = "${index}${value}"; | ||
} | ||
static method main() → dynamic { | ||
self::C? c = new self::C::•(); | ||
self::expect("", let final self::C? #t3 = c in #t3.{core::Object::==}(null) ?{core::String?} null : #t3{self::C}.{self::C::m}); | ||
self::_extension#0|set#setter(c, "42"); | ||
self::expect("42", let final self::C? #t4 = c in #t4.{core::Object::==}(null) ?{core::String?} null : #t4{self::C}.{self::C::m}); | ||
self::_extension#0|[]=(c, 42, "87"); | ||
self::expect("4287", let final self::C? #t5 = c in #t5.{core::Object::==}(null) ?{core::String?} null : #t5{self::C}.{self::C::m}); | ||
} | ||
static method expect(dynamic expected, dynamic actual) → dynamic { | ||
if(!expected.{core::Object::==}(actual)) | ||
throw "Expected ${expected}, actual ${actual}"; | ||
} |
34 changes: 34 additions & 0 deletions
34
pkg/front_end/testcases/nnbd/nullable_setter.dart.strong.transformed.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
class C extends core::Object { | ||
field core::String m = ""; | ||
synthetic constructor •() → self::C | ||
: super core::Object::•() | ||
; | ||
set setter(core::String v) → void {} | ||
operator []=(core::int index, core::String value) → void {} | ||
} | ||
extension _extension#0 on self::C? { | ||
operator []= = self::_extension#0|[]=; | ||
set setter = self::_extension#0|set#setter; | ||
} | ||
static method _extension#0|set#setter(final self::C? #this, core::String v) → void { | ||
let final self::C? #t1 = #this in #t1.{core::Object::==}(null) ?{core::String?} null : #t1{self::C}.{self::C::m} = v; | ||
} | ||
static method _extension#0|[]=(final self::C? #this, core::int index, core::String value) → void { | ||
let final self::C? #t2 = #this in #t2.{core::Object::==}(null) ?{core::String?} null : #t2{self::C}.{self::C::m} = "${index}${value}"; | ||
} | ||
static method main() → dynamic { | ||
self::C? c = new self::C::•(); | ||
self::expect("", let final self::C? #t3 = c in #t3.{core::Object::==}(null) ?{core::String?} null : #t3{self::C}.{self::C::m}); | ||
self::_extension#0|set#setter(c, "42"); | ||
self::expect("42", let final self::C? #t4 = c in #t4.{core::Object::==}(null) ?{core::String?} null : #t4{self::C}.{self::C::m}); | ||
self::_extension#0|[]=(c, 42, "87"); | ||
self::expect("4287", let final self::C? #t5 = c in #t5.{core::Object::==}(null) ?{core::String?} null : #t5{self::C}.{self::C::m}); | ||
} | ||
static method expect(dynamic expected, dynamic actual) → dynamic { | ||
if(!expected.{core::Object::==}(actual)) | ||
throw "Expected ${expected}, actual ${actual}"; | ||
} |
10 changes: 10 additions & 0 deletions
10
pkg/front_end/testcases/nnbd/nullable_setter.dart.textual_outline.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class C { | ||
String m = ""; | ||
void set setter(String v) { } | ||
void operator []=(int index, String value) { } | ||
} | ||
extension on ; | ||
C; | ||
? { void set setter(String v) { this?.m = v; } void operator []=(int index, String value) { this?.m = '$index$value'; } } | ||
main() { } | ||
expect(expected, actual) { } |
34 changes: 34 additions & 0 deletions
34
pkg/front_end/testcases/nnbd/nullable_setter.dart.weak.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
class C extends core::Object { | ||
field core::String m = ""; | ||
synthetic constructor •() → self::C | ||
: super core::Object::•() | ||
; | ||
set setter(core::String v) → void {} | ||
operator []=(core::int index, core::String value) → void {} | ||
} | ||
extension _extension#0 on self::C? { | ||
operator []= = self::_extension#0|[]=; | ||
set setter = self::_extension#0|set#setter; | ||
} | ||
static method _extension#0|set#setter(final self::C? #this, core::String v) → void { | ||
let final self::C? #t1 = #this in #t1.{core::Object::==}(null) ?{core::String?} null : #t1{self::C}.{self::C::m} = v; | ||
} | ||
static method _extension#0|[]=(final self::C? #this, core::int index, core::String value) → void { | ||
let final self::C? #t2 = #this in #t2.{core::Object::==}(null) ?{core::String?} null : #t2{self::C}.{self::C::m} = "${index}${value}"; | ||
} | ||
static method main() → dynamic { | ||
self::C? c = new self::C::•(); | ||
self::expect("", let final self::C? #t3 = c in #t3.{core::Object::==}(null) ?{core::String?} null : #t3{self::C}.{self::C::m}); | ||
self::_extension#0|set#setter(c, "42"); | ||
self::expect("42", let final self::C? #t4 = c in #t4.{core::Object::==}(null) ?{core::String?} null : #t4{self::C}.{self::C::m}); | ||
self::_extension#0|[]=(c, 42, "87"); | ||
self::expect("4287", let final self::C? #t5 = c in #t5.{core::Object::==}(null) ?{core::String?} null : #t5{self::C}.{self::C::m}); | ||
} | ||
static method expect(dynamic expected, dynamic actual) → dynamic { | ||
if(!expected.{core::Object::==}(actual)) | ||
throw "Expected ${expected}, actual ${actual}"; | ||
} |
34 changes: 34 additions & 0 deletions
34
pkg/front_end/testcases/nnbd/nullable_setter.dart.weak.transformed.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
|
||
class C extends core::Object { | ||
field core::String m = ""; | ||
synthetic constructor •() → self::C | ||
: super core::Object::•() | ||
; | ||
set setter(core::String v) → void {} | ||
operator []=(core::int index, core::String value) → void {} | ||
} | ||
extension _extension#0 on self::C? { | ||
operator []= = self::_extension#0|[]=; | ||
set setter = self::_extension#0|set#setter; | ||
} | ||
static method _extension#0|set#setter(final self::C? #this, core::String v) → void { | ||
let final self::C? #t1 = #this in #t1.{core::Object::==}(null) ?{core::String?} null : #t1{self::C}.{self::C::m} = v; | ||
} | ||
static method _extension#0|[]=(final self::C? #this, core::int index, core::String value) → void { | ||
let final self::C? #t2 = #this in #t2.{core::Object::==}(null) ?{core::String?} null : #t2{self::C}.{self::C::m} = "${index}${value}"; | ||
} | ||
static method main() → dynamic { | ||
self::C? c = new self::C::•(); | ||
self::expect("", let final self::C? #t3 = c in #t3.{core::Object::==}(null) ?{core::String?} null : #t3{self::C}.{self::C::m}); | ||
self::_extension#0|set#setter(c, "42"); | ||
self::expect("42", let final self::C? #t4 = c in #t4.{core::Object::==}(null) ?{core::String?} null : #t4{self::C}.{self::C::m}); | ||
self::_extension#0|[]=(c, 42, "87"); | ||
self::expect("4287", let final self::C? #t5 = c in #t5.{core::Object::==}(null) ?{core::String?} null : #t5{self::C}.{self::C::m}); | ||
} | ||
static method expect(dynamic expected, dynamic actual) → dynamic { | ||
if(!expected.{core::Object::==}(actual)) | ||
throw "Expected ${expected}, actual ${actual}"; | ||
} |