Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type variables are not in scope of static methods #643

Closed
peter-ahe-google opened this issue Nov 30, 2011 · 10 comments
Closed

Type variables are not in scope of static methods #643

peter-ahe-google opened this issue Nov 30, 2011 · 10 comments
Assignees

Comments

@peter-ahe-google
Copy link
Contributor

$ cat fisk.dart
class T {
  toString() => "class T";
}

class Foo<T> {
  static m() => new T();
}

main() {
  print(Foo.m());
}

$ dartc_test fisk.dart
fisk.dart:6: cannot access type variable T in static context
     5: class Foo<T> {
     6: static m() => new T();
fisk.dart:6: New expression does not resolve to a constructor
     5: class Foo<T> {
     6: static m() => new T();
Compilation failed with 2 problems.

$ frogsh fisk.dart
We are sorry, but... no constructors on type parameters yet

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
CompilerException: We are sorry, but... no constructors on type parameters yet
    at World._message (frogsh:23264:5)
    at World.internalError (frogsh:23287:8)
    at ParameterType.getConstructor (frogsh:21501:18)
    at ParameterType.getConstructor$1 (frogsh:21525:15)
    at MethodGenerator.visitNewExpression (frogsh:14264:16)
    at lang_NewExpression.visit (frogsh:20744:18)
    at MethodGenerator.visitValue (frogsh:13523:20)
    at MethodGenerator.visitTypedValue (frogsh:13528:15)
    at MethodGenerator.visitReturnStatement (frogsh:13601:22)
    at ReturnStatement.visit (frogsh:20362:18)

$ dart fisk.dart
class T

@DartBot
Copy link

DartBot commented Dec 8, 2011

This comment was originally written by [email protected]


Just to make sure I understand, the issue is that T is both a type variable and a top level class. We shouldn't warn about T inside of m() as a type variable because it isn't in scope, and instead should keep looking up the scope tree to resolve the symbol.

@DartBot
Copy link

DartBot commented Dec 8, 2011

This comment was originally written by [email protected]


Set owner to [email protected].
Added Started label.

@peter-ahe-google
Copy link
Contributor Author

Sorry I should have given more details. It is not obvious what I consider a problem here.

The only thing I think is wrong with the errors from dartc is that there are two. One error message should be sufficient.

@peter-ahe-google
Copy link
Contributor Author

Sorry, I was wrong. The spec says that the type variable isn't in scope.

I think a warning would be nice, though.

@DartBot
Copy link

DartBot commented Jan 18, 2012

This comment was originally written by [email protected]


Review for dartc up at http://codereview.chromium.org/9250017/

The following code now runs to completion, printing one warning (already added by Konstantin last week)

$ cat /tmp/fish.dart
class T {
  toString() => "class T";
}

class Foo<T> {
  static m() => new T().toString();
}

main() {
  print(Foo.m());
}

$ dartc_test /tmp/fish.dart
file:/tmp/fish.dart:5: Type variable 'T' is hiding 'CLASS T' at fish.dart::1:7
     4:
     5: class Foo<T> {
class T

If you rename class T to another name, you get:

$ dartc_test /tmp/fish.dart
file:/tmp/fish.dart:6: cannot access type variable T in static context
     5: class Foo<T> {
     6: static m() => new T().toString();
file:/tmp/fish.dart:6: New expression does not resolve to a constructor
     5: class Foo<T> {
     6: static m() => new T().toString();
Compilation failed with 2 problems.

@DartBot
Copy link

DartBot commented Jan 19, 2012

This comment was originally written by [email protected]


r3434


Added Fixed label.

@fsc8000
Copy link
Contributor

fsc8000 commented Nov 21, 2012

Reopened since the corresponding test, after re-enabled, currently fails on the VM, dart2js and dartc.


cc @peter-ahe-google.
Removed the owner.
Added Triaged label.

@peter-ahe-google
Copy link
Contributor Author

What is the corresponding test? Shouldn't there be a bug for each area that is failing that test?


Set owner to @fsc8000.
Added NeedsInfo label.

@fsc8000
Copy link
Contributor

fsc8000 commented Nov 22, 2012

I added the following line to the language.status and language_dart2js.status files:

+type_variable_shadows_class_test: Fail # Issue #643

@fsc8000
Copy link
Contributor

fsc8000 commented Nov 22, 2012

This is working on all platform. The test is invalid since the expected behavior has changed. There is already a negative test for the correct behavior (tests/language/type_variable_static_context_negative_test.dart)

https://code.google.com/p/dart/source/detail?r=15247


Added Fixed label.

copybara-service bot pushed a commit that referenced this issue Jun 15, 2022
…ions)

https://dart.googlesource.com/protobuf/+log/408f69b98b2d..3105588b8e51

2022-06-15 [email protected] Remove unused function
2022-06-15 [email protected] Simplify PbList implementation, fix freezing (#626)
2022-06-15 [email protected] Remove frozen message modification handling (#643)
2022-06-15 [email protected] Bump version number for development, add changelog entry for #644
2022-06-15 [email protected] Remove ReadonlyMessageMixin (#644)
2022-06-15 [email protected] Release protobuf-2.1.0, protoc_plugin-20.0.1 (#677)
2022-06-14 [email protected] Specify `GeneratedMessage operator==` argument type (#675)
2022-06-14 [email protected] Add changes since the last protobuf release to CHANGELOG (#619)
2022-06-10 [email protected] Tweak consts.dart docs (#674)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/dart-protobuf-dart-sdk
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Dart Protobuf Support: https://github.com/dart-lang/protobuf/issues
To file a bug in Dart SDK: https://github.com/dart-lang/sdk/issues

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

Tbr: [email protected]
Change-Id: If0f2beb1f63ef9a7527abaa116d883ef0fd4b6c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/248620
Commit-Queue: Nate Bosch <[email protected]>
Reviewed-by: Nate Bosch <[email protected]>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants