dartanalyzer not picking up extension-methods experiment defined in analysis options

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

Author: Fantashit

4 thoughts on “dartanalyzer not picking up extension-methods experiment defined in analysis options

  1. 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.

  2. 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"
    
  3. It was fixed after I changed the sdk enviorment to

    environment:
      sdk: ">=2.6.0 <3.0.0"
    

    this work for me

  4. @pq I had this raised at Dart-Code/Dart-Code#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!).

Comments are closed.