Comments (5)
Try switching DartPad to use the beta or master channels (bottom right corner), and see if the issue goes away.
If it does, then it's already fixed.
If I do that, https://dartpad.dev/?id=0a04aa2c6b4ea7c668fb002b83fc91c3&channel=beta, then the error goes away from the beta channel and onwards.
from sdk.
I can't reproduce this behavior using this program (using the DartPad stable or main channel):
extension type HeightWidth(num size) implements num {
HeightWidth operator /(num denominator) {
final b = size / denominator;
return HeightWidth(size / denominator);
}
HeightWidth operator *(num multiplier) {
return HeightWidth(size * multiplier);
}
HeightWidth times(num multiplier) {
return HeightWidth(size * multiplier);
}
String get asString => 'HeightWidth($size)';
}
final d_margin1 = HeightWidth(1); // Was undefined.
final HeightWidth d_margin05 = d_margin1 / 2;
final HeightWidth d_margin1025 = d_margin1 * 1.25;
final HeightWidth d_margin105 = d_margin1.times(1.5);
void main() {
print('${d_margin05.asString}, '
'${d_margin1025.asString}, '
'${d_margin105.asString}');
}
This program is accepted, it runs, and the output seems to be as expected. (We have to use a name which isn't a member of Object
because extension types can't redeclare such members, so we use asString
where we would perhaps have preferred to use toString()
)
Perhaps your tool chain is too old? What's the version?
from sdk.
The only issue I see with the code is the typo:
final HeightWIdth d_margin1025 = d_margin1 *1.25;
// This gives syntax error as it returns a double, not HeightWidth
The I
in WIdth
is capitalized.
That should not give a syntax error.
The declaration of d_margin1
is not in the example, so even without the typo, we can't run it as provided.
Can you provide a complete program which has this issue, say how you execute it, and show the actual error message that you get?
(Actually, if I fix the typo, add a d_margin1
, and run it in dartpad.dev on the stable branch, the analyzer does show an error for the multiplication:
A value of type 'double' can't be assigned to a variable of type 'HeightWidth'.
That error is gone on the beta and master branches, so it's probably that bug in the analyzer which causes the error to be shown. It's only cosmetic, the compiler will accept the code. And if that is the issue here, it has been fixed.)
from sdk.
Thank you for the response.
I am really sorry for the typo while posting the issue here. The typo is not present in my editor. (I have updated the original post's spelling also.)
The same code that you are writing is giving me errors in Dartpad also. Please look at this screenshot.
from sdk.
It worked when I switched to the latest. Thanks for the trouble.
from sdk.
Related Issues (20)
- `Swap with parent/child` assist should work on single-child `Flex`
- avoid_init_to_null fix of late initialize causes runtime errors HOT 1
- [dart2wasm] iFrame locks position on transition into view HOT 4
- [CP] [vm/ffi] Fix variadic arguments on MacOS Arm64 HOT 2
- analyzer plugins do not reanalyze non-Dart files when they are modified HOT 7
- `dart fix` output case inconsistency HOT 1
- Import `new_library` assist should auto-remove unecessary import HOT 2
- Add more context to `not_a_type` diagnostics HOT 1
- Dart2Wasm compiler fails building when dart:ffi library is conditionally imported HOT 15
- [Null-aware elements] [meta] Null-aware elements implementation
- [resource_identifiers] `UsageQueryable` proposal HOT 4
- Possible index error in _processExpressionCompilationRequest HOT 1
- Different async timing whether using vm, node, dart2js and dart2wasm HOT 3
- Macros: Expose doc comments of a declaration
- [Null-aware elements] Implement parser changes
- [Null-aware elements] CFE Implementation
- Make analysis server/IDEs show the distinction between fields and getters accurately and consistently
- Linter: `avoid_dynamic_calls` should allow `<any>.runtimeType` HOT 1
- The return type 'String' isn't a 'String', as required by the closure's context HOT 2
- Flaky coverage/package:front_end/src/fasta/type_inference/inference_visitor_base.dart on front-end-linux-release-x64-try
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.