Discussion:
[dart-misc] Overriding fields in strong mode
'Samuel Rawlins' via Dart Misc
2017-03-11 00:04:46 UTC
Permalink
Hey Dart strong mode experts,

I am wondering why we cannot override fields in strong mode (without
changing type). Take this example:

class A {
int a;
}

class B extends A {
@deprecated
int a;
}

https://dartpad.dartlang.org/69bf3a7802e742e87a9c82b7a641a30a

yields the error: "Field declaration A.a cannot be overridden in B."

I think there are probably many reasons to want to annotate a field from
your super class (mark it @deprecated, or to observe it, or declare it
non-null, etc), and the only way to annotate it is to re-declare it.

A) Why can we not re-declare a field, if we don't change it's type or
access?
B) How else might you annotate a field in your super class?
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Frank Pepermans
2017-03-11 00:16:29 UTC
Permalink
Never used the annotation myself, but did you try @virtual?
https://github.com/dart-lang/sdk/issues/27384

On Sat, 11 Mar 2017, 01:04 'Samuel Rawlins' via Dart Misc, <
Post by 'Samuel Rawlins' via Dart Misc
Hey Dart strong mode experts,
I am wondering why we cannot override fields in strong mode (without
class A {
int a;
}
class B extends A {
@deprecated
int a;
}
https://dartpad.dartlang.org/69bf3a7802e742e87a9c82b7a641a30a
yields the error: "Field declaration A.a cannot be overridden in B."
I think there are probably many reasons to want to annotate a field from
non-null, etc), and the only way to annotate it is to re-declare it.
A) Why can we not re-declare a field, if we don't change it's type or
access?
B) How else might you annotate a field in your super class?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
'Samuel Rawlins' via Dart Misc
2017-03-11 00:44:48 UTC
Permalink
That is almost what I'm looking for, Frank. Thanks for the tip.

However, I'm looking at the issue where you don't control/own the super
class. In particular if you are extending dart:html's Element, or something
really distant from your code, in a separate package.

Here's the announcement:
https://github.com/dart-lang/sdk/blob/master/CHANGELOG.md#strong-mode-1
Post by Frank Pepermans
https://github.com/dart-lang/sdk/issues/27384
On Sat, 11 Mar 2017, 01:04 'Samuel Rawlins' via Dart Misc, <
Post by 'Samuel Rawlins' via Dart Misc
Hey Dart strong mode experts,
I am wondering why we cannot override fields in strong mode (without
class A {
int a;
}
class B extends A {
@deprecated
int a;
}
https://dartpad.dartlang.org/69bf3a7802e742e87a9c82b7a641a30a
yields the error: "Field declaration A.a cannot be overridden in B."
I think there are probably many reasons to want to annotate a field from
non-null, etc), and the only way to annotate it is to re-declare it.
A) Why can we not re-declare a field, if we don't change it's type or
access?
B) How else might you annotate a field in your super class?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
'Vijay Menon' via Dart Misc
2017-03-11 01:00:47 UTC
Permalink
FYI - this is slated to be supported again in 1.23 (overriding without
virtual):

https://github.com/dart-lang/sdk/issues/28117

That said, in your example below, instances of type B will end up with two
field slots for 'a', which might not be what you want.

On Fri, Mar 10, 2017 at 4:44 PM, 'Samuel Rawlins' via Dart Misc <
Post by 'Samuel Rawlins' via Dart Misc
That is almost what I'm looking for, Frank. Thanks for the tip.
However, I'm looking at the issue where you don't control/own the super
class. In particular if you are extending dart:html's Element, or something
really distant from your code, in a separate package.
Here's the announcement: https://github.com/dart-lang/sdk/blob/master/
CHANGELOG.md#strong-mode-1
Post by Frank Pepermans
https://github.com/dart-lang/sdk/issues/27384
On Sat, 11 Mar 2017, 01:04 'Samuel Rawlins' via Dart Misc, <
Post by 'Samuel Rawlins' via Dart Misc
Hey Dart strong mode experts,
I am wondering why we cannot override fields in strong mode (without
class A {
int a;
}
class B extends A {
@deprecated
int a;
}
https://dartpad.dartlang.org/69bf3a7802e742e87a9c82b7a641a30a
yields the error: "Field declaration A.a cannot be overridden in B."
I think there are probably many reasons to want to annotate a field from
non-null, etc), and the only way to annotate it is to re-declare it.
A) Why can we not re-declare a field, if we don't change it's type or
access?
B) How else might you annotate a field in your super class?
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to
http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google
Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Loading...