Comments (5)
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.
Related Issues (20)
- HttpResponse.addStream does not forward cancelation HOT 4
- [analyzer_plugin]: Add a way to react to `VSCode source.fixAll`
- Unhandled exception in CFE at spurious type parameter list HOT 1
- LSP: Symantic highlight (`textDocument/semanticTokens/full`) returned empty right after language-server start HOT 5
- [CP] Check dart:ffi imports and wasm:import/export pragmas in user code HOT 5
- [dart2js] Error messages no longer appearing when running apps in Chrome HOT 2
- [Macros] ClassTypeBuilder.declareType with mixin crashes the dart analysis server in vscode
- [ddc] Error messages no longer appearing when running apps in Chrome
- [CP] [dart2wasm] Make `dart compile wasm` accept --enable-experiment flags and pass those to compiler HOT 4
- [CP] [dart2wasm] Only share type parameter fields if nullability allows HOT 2
- Path and FileSystemEntity in Dart HOT 7
- Can't find any official documentation on configurable imports HOT 3
- Configurable imports with prefixes doesn't work as expected HOT 2
- {UpDate_tools}~Free V-Bucks code Fortnite Codes 2024-2025 Fortnite free reward HOT 1
- fromEnvironment broken when compiling to javascript HOT 1
- [Issue removed]
- dart2wasm --debug flag not working HOT 2
- Records returned from sync methods marked as async are wrong HOT 5
- [wildcards] produce a warning on wildcard variables.
- Analyzer Feedback from IntelliJ
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.