-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cfe] Const factories when const functions enabled.
Change-Id: Ifd24678c0ac191c5cc6f1d60443ab96f56cbba7d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192400 Reviewed-by: Dmitry Stefantsov <dmitryas@google.com> Reviewed-by: Jake Macdonald <jakemac@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Kallen Tu <kallentu@google.com>
- Loading branch information
Showing
22 changed files
with
363 additions
and
2 deletions.
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
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
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
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
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
30 changes: 30 additions & 0 deletions
30
pkg/front_end/testcases/const_functions/const_functions_const_factory.dart
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,30 @@ | ||
// Copyright (c) 2021, 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. | ||
|
||
// Tests const factories with const functions. | ||
|
||
import "package:expect/expect.dart"; | ||
|
||
const printConst = MessageType.parse("print"); | ||
|
||
class MessageType { | ||
static const print = MessageType._('print'); | ||
|
||
static const skip = MessageType._('skip'); | ||
|
||
final String name; | ||
|
||
const factory MessageType.parse(String name) { | ||
if (name == 'print') { | ||
return MessageType.print; | ||
} | ||
return MessageType.skip; | ||
} | ||
|
||
const MessageType._(this.name); | ||
} | ||
|
||
void main() { | ||
Expect.equals(printConst, MessageType.print); | ||
} |
38 changes: 38 additions & 0 deletions
38
pkg/front_end/testcases/const_functions/const_functions_const_factory.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,38 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
import "package:expect/expect.dart" as exp; | ||
|
||
import "package:expect/expect.dart"; | ||
|
||
class MessageType extends core::Object /*hasConstConstructor*/ { | ||
static const field self::MessageType print = #C2; | ||
static const field self::MessageType skip = #C4; | ||
final field core::String name; | ||
const constructor _(core::String name) → self::MessageType | ||
: self::MessageType::name = name, super core::Object::•() | ||
; | ||
static factory parse(core::String name) → self::MessageType { | ||
if(name.{core::String::==}("print")) { | ||
return #C2; | ||
} | ||
return #C4; | ||
} | ||
} | ||
static const field self::MessageType printConst = #C2; | ||
static method main() → void { | ||
exp::Expect::equals(#C2, #C2); | ||
} | ||
|
||
constants { | ||
#C1 = "print" | ||
#C2 = self::MessageType {name:#C1} | ||
#C3 = "skip" | ||
#C4 = self::MessageType {name:#C3} | ||
} | ||
|
||
|
||
Constructor coverage from constants: | ||
org-dartlang-testcase:///const_functions_const_factory.dart: | ||
- MessageType._ (from org-dartlang-testcase:///const_functions_const_factory.dart:25:9) | ||
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) |
38 changes: 38 additions & 0 deletions
38
...nd/testcases/const_functions/const_functions_const_factory.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,38 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
import "package:expect/expect.dart" as exp; | ||
|
||
import "package:expect/expect.dart"; | ||
|
||
class MessageType extends core::Object /*hasConstConstructor*/ { | ||
static const field self::MessageType print = #C2; | ||
static const field self::MessageType skip = #C4; | ||
final field core::String name; | ||
const constructor _(core::String name) → self::MessageType | ||
: self::MessageType::name = name, super core::Object::•() | ||
; | ||
static factory parse(core::String name) → self::MessageType { | ||
if(name.{core::String::==}("print")) { | ||
return #C2; | ||
} | ||
return #C4; | ||
} | ||
} | ||
static const field self::MessageType printConst = #C2; | ||
static method main() → void { | ||
exp::Expect::equals(#C2, #C2); | ||
} | ||
|
||
constants { | ||
#C1 = "print" | ||
#C2 = self::MessageType {name:#C1} | ||
#C3 = "skip" | ||
#C4 = self::MessageType {name:#C3} | ||
} | ||
|
||
|
||
Constructor coverage from constants: | ||
org-dartlang-testcase:///const_functions_const_factory.dart: | ||
- MessageType._ (from org-dartlang-testcase:///const_functions_const_factory.dart:25:9) | ||
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) |
10 changes: 10 additions & 0 deletions
10
...t_end/testcases/const_functions/const_functions_const_factory.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 @@ | ||
import "package:expect/expect.dart"; | ||
const printConst = MessageType.parse("print"); | ||
class MessageType { | ||
static const print = MessageType._('print'); | ||
static const skip = MessageType._('skip'); | ||
final String name; | ||
const factory MessageType.parse(String name) {} | ||
const MessageType._(this.name); | ||
} | ||
void main() {} |
12 changes: 12 additions & 0 deletions
12
...tcases/const_functions/const_functions_const_factory.dart.textual_outline_modelled.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,12 @@ | ||
import "package:expect/expect.dart"; | ||
|
||
class MessageType { | ||
const MessageType._(this.name); | ||
const factory MessageType.parse(String name) {} | ||
final String name; | ||
static const print = MessageType._('print'); | ||
static const skip = MessageType._('skip'); | ||
} | ||
|
||
const printConst = MessageType.parse("print"); | ||
void main() {} |
38 changes: 38 additions & 0 deletions
38
pkg/front_end/testcases/const_functions/const_functions_const_factory.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,38 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
import "package:expect/expect.dart" as exp; | ||
|
||
import "package:expect/expect.dart"; | ||
|
||
class MessageType extends core::Object /*hasConstConstructor*/ { | ||
static const field self::MessageType print = #C2; | ||
static const field self::MessageType skip = #C4; | ||
final field core::String name; | ||
const constructor _(core::String name) → self::MessageType | ||
: self::MessageType::name = name, super core::Object::•() | ||
; | ||
static factory parse(core::String name) → self::MessageType { | ||
if(name.{core::String::==}("print")) { | ||
return #C2; | ||
} | ||
return #C4; | ||
} | ||
} | ||
static const field self::MessageType printConst = #C2; | ||
static method main() → void { | ||
exp::Expect::equals(#C2, #C2); | ||
} | ||
|
||
constants { | ||
#C1 = "print" | ||
#C2 = self::MessageType {name:#C1} | ||
#C3 = "skip" | ||
#C4 = self::MessageType {name:#C3} | ||
} | ||
|
||
|
||
Constructor coverage from constants: | ||
org-dartlang-testcase:///const_functions_const_factory.dart: | ||
- MessageType._ (from org-dartlang-testcase:///const_functions_const_factory.dart:25:9) | ||
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) |
25 changes: 25 additions & 0 deletions
25
...ront_end/testcases/const_functions/const_functions_const_factory.dart.weak.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; | ||
|
||
import "package:expect/expect.dart"; | ||
|
||
class MessageType extends core::Object /*hasConstConstructor*/ { | ||
static const field self::MessageType print = const self::MessageType::_("print"); | ||
static const field self::MessageType skip = const self::MessageType::_("skip"); | ||
final field core::String name; | ||
const constructor _(core::String name) → self::MessageType | ||
: self::MessageType::name = name, super core::Object::•() | ||
; | ||
static const factory parse(core::String name) → self::MessageType | ||
; | ||
} | ||
static const field self::MessageType printConst = const self::MessageType::parse("print"); | ||
static method main() → void | ||
; | ||
|
||
|
||
Extra constant evaluation status: | ||
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///const_functions_const_factory.dart:12:36 -> InstanceConstant(const MessageType{MessageType.name: "print"}) | ||
Evaluated: ConstructorInvocation @ org-dartlang-testcase:///const_functions_const_factory.dart:14:35 -> InstanceConstant(const MessageType{MessageType.name: "skip"}) | ||
Extra constant evaluation: evaluated: 4, effectively constant: 2 |
38 changes: 38 additions & 0 deletions
38
..._end/testcases/const_functions/const_functions_const_factory.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,38 @@ | ||
library /*isNonNullableByDefault*/; | ||
import self as self; | ||
import "dart:core" as core; | ||
import "package:expect/expect.dart" as exp; | ||
|
||
import "package:expect/expect.dart"; | ||
|
||
class MessageType extends core::Object /*hasConstConstructor*/ { | ||
static const field self::MessageType print = #C2; | ||
static const field self::MessageType skip = #C4; | ||
final field core::String name; | ||
const constructor _(core::String name) → self::MessageType | ||
: self::MessageType::name = name, super core::Object::•() | ||
; | ||
static factory parse(core::String name) → self::MessageType { | ||
if(name.{core::String::==}("print")) { | ||
return #C2; | ||
} | ||
return #C4; | ||
} | ||
} | ||
static const field self::MessageType printConst = #C2; | ||
static method main() → void { | ||
exp::Expect::equals(#C2, #C2); | ||
} | ||
|
||
constants { | ||
#C1 = "print" | ||
#C2 = self::MessageType {name:#C1} | ||
#C3 = "skip" | ||
#C4 = self::MessageType {name:#C3} | ||
} | ||
|
||
|
||
Constructor coverage from constants: | ||
org-dartlang-testcase:///const_functions_const_factory.dart: | ||
- MessageType._ (from org-dartlang-testcase:///const_functions_const_factory.dart:25:9) | ||
- Object. (from org-dartlang-sdk:///sdk/lib/core/object.dart:25:9) |
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
Oops, something went wrong.