Skip to content

Doc comments in typedefs for record types can't reference field names #60332

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

Open
GiancarloCante opened this issue Mar 16, 2025 · 4 comments
Open
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-doc

Comments

@GiancarloCante
Copy link

In doc comments for typedefs that define record types, using square brackets ([ ]) to reference field names does not recognize them as in-scope identifiers. This makes it impossible to link to those fields in documentation.

This issue specifically applies to record type field names, both positional and named, when used inside a typedef.

Reproduction

/// - [a] BAD: The referenced name isn't visible in scope.
/// - [b] BAD: The referenced name isn't visible in scope.
/// - [T] GOOD: The referenced name is visible in scope.
typedef Record1<T> = (
  int a,
  String b,
);

/// - [a] BAD: The referenced name isn't visible in scope.
/// - [b] BAD: The referenced name isn't visible in scope.
/// - [T] GOOD: The referenced name is visible in scope.
typedef Record2<T> = ({
  int a,
  String b,
});

Expected behavior

The field names a and b should be treated as in-scope identifiers, and [a] and [b] should be linkable in the doc comments.

Actual behavior

  • [T] is correctly recognized and linkable.
  • [a] and [b] are not recognized, despite being valid field names in the record type alias.

Environment

  • Dart SDK 3.7
@lrhn lrhn added docs-api area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-doc and removed docs-api labels Mar 16, 2025
@FMorschel
Copy link
Contributor

I'll take a look into this.

FYI @srawlins

@FMorschel
Copy link
Contributor

Thinking about this a bit more, I don't think this is doable right now. I once opened Dart-Code/Dart-Code#5294 for something related to record fields but we still have #53024 opened to support renaming them. While the last one is not closed, I'm not sure this will be possible.

@eernstg
Copy link
Member

eernstg commented Mar 17, 2025

Note that the named getters (that is, a and b in Record2) should be in scope, in the same way as, say, instance variable declarations in a class. The names a and b in Record1 are not in scope anywhere. They are basically just comments, and it is not so obvious that they should be treated like a name which is in scope.

@FMorschel
Copy link
Contributor

it is not so obvious that they should be treated like a name which is in scope.

It is probably doable to show them (both) there, but I'm not sure we should. As mentioned above, we currently don't have any internal element for them, so Go to Definition (CTRL + Click) would probably not work and even if we made it work here it would not anywhere else, currently.

I'd like your opinion here too if possible @bwilkerson.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-doc
Projects
None yet
Development

No branches or pull requests

4 participants