Comments (6)
Also this example :
void main() {
MyClass myClass = MyClass();
print(myClass.i);
print(myClass.j);
}
class MyClass {
//Should not allow to initialize by themselves.
late int i = this.i;
// And also should not allow to initialize by others who are dependent on it.
late int j = this.k;
late int k = this.j;
}
from sdk.
An initializer not being self referential is probably a good warning.
I can write a successfull program with a self reference, so it's not necessarily a bug, but I can't find up with any reasonable reason for writing a program like that, so giving a warning unconditionally seems appropriate.
Marking as analyzer.
We could try to disallow the self reference in the language, but to do it properly, we'd want to catch mutually recursive declarations too, which is not trivial. A heuristic warning if the declaration contains direct self reference matches an analyzer warning better.
We can detect self references in constants because we actually evaluate them at compile time.
(A "successful" self-referential initializer could be:
class Weird {
final int _defaultLevel;
Weird(int defaultLevel) : _defaultLevel = defaultLevel;
late String _levelString = (this._level, this._levelString).$2; // Initialize level if it isn't.
late int _level = (_levelString = _defaultLevel.toString(), _defaultLevel).$2;
}
Here the initialil this._level
will assign to _levelString
, which it can then successfully read.
Just never do something like that, it's too hard to read.)
from sdk.
Thank you sir for updating the correct title for me :)
But, the analyzer needs to give a compile time error, not a warning. because the program is crashing due to a stack overflow situation.
from sdk.
Stack overflow is a runtime error. There are lots of ways to write programs with runtime errors, that the analyzer cannot recognize at compiler time.
The analyzer doesn't generally introduce compile time errors, it only reports errors that are specified in the language specification.
And I don't see us trying to catch this error in the specification.
For "this is probably an error"-cases, the analyzer reports a warning. You can always change the diagnostic to an error if you want to.
from sdk.
ok sir, thanks for replying to my issue 😊.
from sdk.
But, the analyzer needs to give a compile time error, not a warning. because the program is crashing due to a stack overflow situation.
According to the late fields specification
- If a variable or field is read from during the process of evaluating its own initializer expression, and no write to the variable has occurred, the read is treated as a first read and the initializer expression is evaluated again.
So, the StackOverflow
in this case is an expected outcome.
from sdk.
Related Issues (20)
- Simplify branch conditions based on ranges & simplify control flow afterwards if condition turns out to be constant
- Issue in number multiplication with 10, 20, etc HOT 4
- Feature Request: Add `--insert-ignore-comments` flag to `dart fix` command for existing code HOT 3
- [vm/core] `_GrowableList.add` has unnecessary bounds check HOT 1
- docImports failing to allow for resolution in some flutter animation library code HOT 4
- Implement augmentations HOT 12
- Support macros when analyzer is used as a library HOT 5
- Is that possible to set breakpoints in the macro code itself? HOT 2
- Inability to Convert Dart BigInt to JSBigInt using new js_interop HOT 1
- Dart CLI commands hang on a slow/unstable internet connection due to analytics HOT 8
- Types Generated using the LibraryTypesMacro throws an error when instantiating HOT 2
- Analyzer Feedback from IntelliJ HOT 1
- Doc comment references cannot resolve an extension member when prefixed by the extended type's name HOT 11
- Different augmented output from macro during development and program running
- pkg/dds/test/devtools_server/instance_reuse_test timing out HOT 4
- [Bug] Uri.parse failes to currectly parse url like: http://user:^@example.com HOT 5
- string.allMatches returns an Iterable of length pattern.length + 1 when aString is empty HOT 6
- [CP] Pub: Fix to using path dependencies in git dependencies on windows HOT 2
- The analyzer encounters an unhandled exception during constant verification in a switch statement HOT 1
- Erasure of extension types in DartObject is blocking adoption of dart:js_interop HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.