Skip to content

static extension methods spec says "Extension members with private names are simply inaccessible in other libraries" #38750

@a-siva

Description

@a-siva

static extension methods spec says "Extension members with private names are simply inaccessible in other libraries" but when I try an example I do not get an error

file1.dart

class C {
  foo() => _foo();
  _foo() {
    try {
      throw "producing a stack trace";
    } catch (e, s) {
      print(s);
    }
  }
  static _sfoo() {
    print("_sfoo");
  }
  static sfoo() => C._sfoo();
}
extension ext on C {
  _bar() {
    try {
      throw "producing a stack trace";
    } catch (e, s) {
      print(s);
    }
  }
}

file.dart

import 'file1.dart';
  
main() {
  C c = new C();
  c._foo();
  C._sfoo();
  c.foo();
  C.sfoo();
  c._bar();
}
/tmp/file.dart:6:5: Error: Method not found: 'C._sfoo'.
  C._sfoo();
    ^^^^^
/tmp/file.dart:5:5: Error: The method '_foo' isn't defined for the class 'C'.
 - 'C' is from '/tmp/file1.dart'.
Try correcting the name to the name of an existing method, or defining a method named '_foo'.
  c._foo();
    ^^^^

file2.dart

import 'file1.dart';

main() {
  C c = new C();
  c._bar();
}
#0      ext|_bar (file:///tmp/file1.dart:19:7)
#1      main (file:///tmp/file2.dart:5:5)
#2      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
#3      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

Metadata

Metadata

Assignees

Labels

P1A high priority bug; for example, a single project is unusable or has many test failureslegacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions