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

Class references not working in method doc strings #3758

Closed
TheFriendlyCoder opened this issue Apr 25, 2024 · 3 comments · Fixed by #3768
Closed

Class references not working in method doc strings #3758

TheFriendlyCoder opened this issue Apr 25, 2024 · 3 comments · Fixed by #3768
Assignees
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@TheFriendlyCoder
Copy link

I've been testing dartdoc in a small project I've been working on, and found some odd behaviour with regards to hyperlinks to classes within the same project not working properly ... but only within method doc strings. Property doc strings don't seem to be affected. Below is a sample snippet to show what I mean:

/// Docstring property reference [MyObject]
Future<MyObject> get myobj async {...}

/// Docstring method reference [MyObject]
Future<int> runOperation(MyObject obj) async {

In this example, the first Doctoring will generate a hyperlink to the MyObject class (ie: from the [MyObject] reference) but the exact same syntax in the second Doctoring will generate text that looks like inline code, similar to MyObject in markdown.

@srawlins
Copy link
Member

Can you show more complete examples? In general, doc comment references (in square brackets) do result in links. There should not be any difference between a getter and a function.

@TheFriendlyCoder
Copy link
Author

I did a little bit more digging and it turns out the root cause of the bug isn't to do with the property vs method thing like I thought, but rather it has to do with the return value from an async method call. The gist is, whatever type(s) are returned as a Future<> do not get hyperlinked properly in the generated docs. Here is the minimal MVP to reproduce:

  1. create a new empty project: dart create package .
  2. create a new file Vehicle.dart with a simple definition like:
class Vehicle {
  int numWheels;

  Vehicle(this.numWheels);
}
  1. Create a new file Person.dart with a simple implementation like:
class Person {
  String name;
  int age;

  Person(this.name, this.age);
}
  1. Create a final file Employee.dart with an implementation like this:
import 'package:package/Person.dart';
import 'package:package/Vehicle.dart';

class Employee extends Person {
  String position;

  Employee(String name, int age, this.position) : super(name, age);

  /// Allows you to get a [Person] who might drive a [Vehicle]
  Future<Vehicle> greeting(Person p) async {
    print('Hello, my name is $name and I am $age years old. I work as a $position. Your name is ${p.name} and you are ${p.age} years old.');
    return Vehicle(4);
  }

  /// Allows you to get a [Person] who might drive a [Vehicle]
  void greeting2(Person p) async {
    print('Hello, my name is $name and I am $age years old. I work as a $position. Your name is ${p.name} and you are ${p.age} years old.');
  }
}
  1. Generate the docs for the project: dart doc
  2. Open the generated docs and browse to the Employee class docs, scoll to the generated output for the greeting and greeting2 methods and you should see something like this:
Screenshot 2024-04-25 at 11 31 02 PM

Note how the [Vehicle] reference in the greeting() doctoring shows up as inline code format (this method has a return type of Future<Vehicle> and the same docstring syntax for greeting2() shows up as a proper hyperlink. Same class, same docstring format, and nearly identical method signatures ... and yet the generated output is different.

@bwilkerson bwilkerson added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Apr 29, 2024
@srawlins srawlins added the P1 A high priority bug; for example, a single project is unusable or has many test failures label May 10, 2024
@srawlins srawlins self-assigned this May 10, 2024
@srawlins
Copy link
Member

Great writeup @TheFriendlyCoder ! This was kind of a spooky bug, I thought surely it couldn't be that just returning a Future<X> means you can no longer refer to X in a doc comment. But that was exactly the bug. 😓 Thanks for your repros. This fix should be released soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants