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

Analyzer doesn't allow type parameter declarations as diagnostic targets in macros #55611

Closed
jakemac53 opened this issue May 1, 2024 · 2 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-macros Implementation of the macros feature P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jakemac53
Copy link
Contributor

I tried adding this to the top of the buildDeclarationsForClass implementation in tests/language/macros/Json/json_serializable.dart:

  @override
  Future<void> buildDeclarationsForClass(
      ClassDeclaration clazz, MemberDeclarationBuilder builder) async {
    if (clazz.typeParameters.isNotEmpty) {
      throw new DiagnosticException(Diagnostic(
          DiagnosticMessage(
              'Cannot be applied to classes with generic type parameters',
              target: clazz.typeParameters.first.asDiagnosticTarget),
          Severity.error));
    }
  }

But it fails with the following error:

type 'TypeParameterDeclarationImpl' is not a subtype of type 'HasElement' in type cast #0      LibraryMacroApplier._addDiagnostics.convertMessage (package:analyzer/src/summary2/macro_application.dart:580:50)
#1      LibraryMacroApplier._addDiagnostics (package:analyzer/src/summary2/macro_application.dart:607:20)
#2      LibraryMacroApplier.executeDeclarationsPhase.<anonymous closure> (package:analyzer/src/summary2/macro_application.dart:335:9)
<asynchronous suspension>
#3      LibraryMacroApplier._runWithCatchingExceptions (package:analyzer/src/summary2/macro_application.dart:860:14)
<asynchronous suspension>
#4      LibraryMacroApplier.executeDeclarationsPhase (package:analyzer/src/summary2/macro_application.dart:317:5)
<asynchronous suspension>
#5      LibraryBuilder.executeMacroDeclarationsPhase (package:analyzer/src/summary2/library_builder.dart:514:19)
<asynchronous suspension>
#6      Linker._executeMacroDeclarationsPhase (package:analyzer/src/summary2/link.dart:348:26)
<asynchronous suspension>
#7      Linker._buildOutlines.<anonymous closure> (package:analyzer/src/summary2/link.dart:225:9)
<asynchronous suspension>
#8      OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:172:14)
<asynchronous suspension>
#9      Linker._buildOutlines (package:analyzer/src/summary2/link.dart:222:5)
<asynchronous suspension>
#10     Linker.link (package:analyzer/src/summary2/link.dart:101:5)
<asynchronous suspension>
#11     link (package:analyzer/src/summary2/link.dart:39:3)
<asynchronous suspension>
#12     LibraryContext.load.loadBundle.<anonymous closure> (package:analyzer/src/dart/analysis/library_context.dart:197:22)
<asynchronous suspension>
#13     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:172:14)
<asynchronous suspension>
#14     LibraryContext.load.loadBundle (package:analyzer/src/dart/analysis/library_context.dart:194:24)
<asynchronous suspension>
#15     LibraryContext.load.<anonymous closure> (package:analyzer/src/dart/analysis/library_context.dart:264:7)
<asynchronous suspension>
#16     PerformanceLog.runAsync (package:analyzer/src/dart/analysis/performance_logger.dart:50:14)
<asynchronous suspension>
#17     LibraryContext.load (package:analyzer/src/dart/analysis/library_context.dart:262:5)
<asynchronous suspension>
#18     AnalysisDriver._analyzeFileImpl.<anonymous closure>.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1352:13)
<asynchronous suspension>
#19     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:172:14)
<asynchronous suspension>
#20     AnalysisDriver._analyzeFileImpl.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1349:9)
<asynchronous suspension>
#21     PerformanceLog.runAsync (package:analyzer/src/dart/analysis/performance_logger.dart:50:14)
<asynchronous suspension>
#22     AnalysisDriver._analyzeFile.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1299:9)
<asynchronous suspension>
#23     OperationPerformanceImpl.runAsync (package:analyzer/src/util/performance/operation_performance.dart:172:14)
<asynchronous suspension>
#24     AnalysisDriver._analyzeFile (package:analyzer/src/dart/analysis/driver.dart:1296:5)
<asynchronous suspension>
#25     AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:1229:9)
<asynchronous suspension>
#26     AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2433:7)
<asynchronous suspension>
@jakemac53 jakemac53 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-macros Implementation of the macros feature labels May 1, 2024
@srawlins srawlins added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 13, 2024
@scheglov
Copy link
Contributor

Store into element model.
https://dart-review.googlesource.com/c/sdk/+/368700

copybara-service bot pushed a commit that referenced this issue May 29, 2024
Bug: #55611
Change-Id: I429de25be81f8d51bfe57131e19ffb4ad737f467
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368700
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
@scheglov
Copy link
Contributor

copybara-service bot pushed a commit that referenced this issue May 30, 2024
…, resolution.

Bug: #55611
Change-Id: Ifd42d594cb9f4bd6a790f406e507ac11fdb63289
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368881
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-macros Implementation of the macros feature P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
Development

No branches or pull requests

3 participants