Last active
February 23, 2023 23:30
-
-
Save misterfourtytwo/f6ccc9a000667bb1f9d6decf3c2b25a2 to your computer and use it in GitHub Desktop.
function tear-off behaves like getter, but is actually syntactic sugar, while function method declaration and getter are incompatible language tokens
This file contains hidden or 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
void p(String x) => print(x); | |
typedef MyFunc = void Function(String); | |
abstract class A { | |
MyFunc? get t; | |
const A(); | |
} | |
class B implements A { | |
@override | |
final MyFunc t = const E().t; | |
B(); | |
} | |
class C implements A { | |
@override | |
MyFunc get t => const E().t; | |
const C(); | |
} | |
class D implements A { | |
@override | |
MyFunc t = const E().t; | |
D(); | |
} | |
class E | |
/// `extends A` <= cannot override function getter as method declaration, likewise in reverse | |
{ | |
void t(String x) => p(x); | |
const E(); | |
} | |
void main() { | |
print(B().t is MyFunc?); | |
print(const C().t is MyFunc?); | |
print(D().t is MyFunc?); | |
print(const E().t is MyFunc?); | |
print(B().t.toString()); | |
print(const C().t.toString()); | |
print(D().t.toString()); | |
print(const E().t.toString()); | |
print(B().t == const E().t); | |
print(const C().t == const E().t); | |
print(D().t == const E().t); | |
print(B().t.runtimeType); | |
print(const C().t.runtimeType); | |
print(D().t.runtimeType); | |
print(const E().t.runtimeType); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment