To reproduce.
mkdir ext_test
cd ext_test
stagehand console-full
Update analysis_options.yaml
to:
analyzer:
enable-experiment:
- extension-methods
and ext_test.dart
to:
extension Foo on Object {
}
run pub get
. Then you can analyze.
[~/tmp/ext_test] $ dartanalyzer .
Analyzing ext_test...
error • This requires the 'extension-methods' experiment to be enabled at lib/ext_test.dart:1:1 • experiment_not_enabled
error • Undefined class 'extension' at lib/ext_test.dart:1:1 • undefined_class
error • Undefined class 'on' at lib/ext_test.dart:1:15 • undefined_class
error • Functions must have an explicit list of parameters at lib/ext_test.dart:1:18 • missing_function_parameters
4 errors found.
This should analyze clean.
[~/tmp/ext_test] $ dart --version
Dart VM version: 2.5.0-edge.89c4f94b602eebb7db71fcf86619a2ef8c8d8085 (Mon Aug 19 17:28:32 2019 +0000) on "macos_x64"
fyi @bwilkerson @stereotype441
Setting the option on the command line works as expected:
[~/tmp/ext_test] $ dartanalyzer --enable-experiment extension-methods .
Analyzing ext_test...
No issues found!
@keertip Ran into this today too. I don't understand why it works for me and not for others. (Keerti and I were using the list notation, but I suspect that won't matter.)
Keerti and I were using the list notation
whoops. That was a mistake. I was using the list version too. (Updated above.)
I did a bit of tracking down and see where the options are getting ignored but fixing it may be destabilizing... Let's discuss tomorrow!
The options not getting picked up was due to the fact that it was a nested package, so the analysis options in the package were not picked up. Adding the options to the top level analysis_options.yaml
got it working.
@keertip: was this using dartanalyzer
or server?
For discussion, here's where it looks like a specified options file is being dropped on the floor:
(that is, specified like dartanalyzer --options analysis_options.yaml
).
Why in this case dartanalyzer .
is not picking up options in the default location is another (likely unrelated) issue.
fyi also @MichaelRFairhurst
I got it to work with both the server and command line, command line with dartanalyzer --enable-experiment=extension-methods .
Did not check if command line analyzer could pick up the from the analysis options file.
Same situation here after updating to Dart 2.8, all of my extension are broken and dartanalyzer --enable-experiment=extension-methods
is not a valid command, aka command not found
@egorikem: is your package nested below another analysis_options.yaml
?
@egorikem what analysis error(s) are you getting?
Also getting an error on extensions class after updating to Dart 2.8. No errors in flutter doctor, on the master channel for the flutter sdk.
This requires the 'extension-methods' experiment to be enabled.
Try enabling this experiment by adding it to the command line when compiling and running.
[✓] Flutter (Channel master, v1.13.8-pre.58, on Mac OS X 10.14.6 18G2022, locale en-US)
• Flutter version 1.13.8-pre.58 at /Users/lukepighetti/development/flutter
• Framework revision fabf4e3d0d (7 hours ago), 2020-01-08 15:28:02 -0800
• Engine revision 46adf73d51
• Dart version 2.8.0 (build 2.8.0-dev.0.0 c0ca187f26)
Can't use extension methods, get the error referenced in this issue.
/fyi @stereotype441
Me too, I downgraded to stable in order to use them
VSCode complains This requires the 'extension-methods' experiment to be enabled. Try enabling this experiment by adding it to the command line when compiling and running.
even though extension-methods flag is enabled.
So when I run dartanalyzer --enable-experiment extension-methods .
it showed
hint • Extension methods weren't supported until version 2.6.0, but this code is required to be able to run on earlier versions. • lib/utils/extensions.dart:1:1 • sdk_version_extension_methods
It was fixed after I changed the sdk enviorment to
environment:
sdk: ">=2.6.0 <3.0.0"
It was fixed after I changed the sdk enviorment to
environment: sdk: ">=2.6.0 <3.0.0"
this work for me
@lukepighetti @Rameshv (and all), do you see a diagnostic (and quick fix) like this when you hover over the error in the IDE?:
Nope, but this seems to have resolved itself when I switched to dev
channel
@pq I had this raised at https://github.com/Dart-Code/Dart-Code/issues/2253 and I saw it too. It just gave the "Try enabling this experiment by adding it to the command line when compiling and running" message.
However I updated the SDK constraint to fix it, and then when I changed it back (and ran pub get
and then restarted VS Code), I got the new message that posted. I can't figure out why I wasn't getting that before (nor get back to a state where I get that message!).
/fyi @stereotype441 @bwilkerson
Given that the extension methods experiment has now shipped as a full feature, I'm guessing this is no longer a problem.
Most helpful comment
VSCode complains
This requires the 'extension-methods' experiment to be enabled. Try enabling this experiment by adding it to the command line when compiling and running.
even though extension-methods flag is enabled.So when I run
dartanalyzer --enable-experiment extension-methods .
it showedIt was fixed after I changed the sdk enviorment to