You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dartdoc bracketed references don't work for inherited members #4114
Bracketed references in dartdoc comments don't get highlighted if the field referred to is a superclass parameter.
For instance, if I have:
/// The callback [TextButton.onPressed] will be called when the button is pressed.
Then the bracketed reference to TextButton.onPressedis not clickable, but:
/// The callback [ButtonStyleButton.onPressed] will be called when the button is pressed.
is clickable. ButtonStyleButton is the superclass for TextButton.
I think this is because the TextButton class inherits its attribute from the parent via the super.onPressed argument in the constructor, but I can't be sure.
I don't think it's specific to super-params, as this has the same behaviour:
class A {
final String myField = '';
}
class B extends A {
}
/// [A.myField] is clickable.
/// [B.myField] is not clickable.
int? a;
@bwilkerson I think this doesn't currently work because in B.myField, myField does not have a staticElement (whereas in A.myField it does). I suspect that's because the comment resolver here only looks in the current class for members:
Should this reference work? And if so, would the correct fix be to walk up prefixElement.allSupertypes to find the first match by name to assign its staticElement?
changed the title [-]Dartdoc bracketed references don't understand `super` parameters.[/-][+]Dartdoc bracketed references don't work for inherited members[/+]on Aug 23, 2022
I don't know what dart doc does with that code, but the analyzer should match it as closely as possible, given the performance constraints it has to operate under.
And if so, would the correct fix be to walk up prefixElement.allSupertypes to find the first match by name to assign its staticElement?
I think we want to walk up the superclass chain first and only look in interfaces when we can't find a member from a supertype. I believe that that's the behavior we use in other features, and it would be good to be consistent. I also think that that's the behavior we'd get from using InheritanceManager3, which is probably the best way to implement such a lookup.
I don't know what dart doc does with that code, but the analyzer should match it as closely as possible, given the performance constraints it has to operate under.
I tested the example above, and it does appear to work:
I also think that that's the behavior we'd get from using InheritanceManager3, which is probably the best way to implement such a lookup.
Activity
DanTup commentedon Aug 23, 2022
I don't think it's specific to super-params, as this has the same behaviour:
@bwilkerson I think this doesn't currently work because in
B.myField,myFielddoes not have astaticElement(whereas inA.myFieldit does). I suspect that's because the comment resolver here only looks in the current class for members:https://github.com/dart-lang/sdk/blob/571f43b004cc32f50418b037af475c6565648c21/pkg/analyzer/lib/src/dart/resolver/comment_reference_resolver.dart#L71-L75
Should this reference work? And if so, would the correct fix be to walk up
prefixElement.allSupertypesto find the first match by name to assign itsstaticElement?[-]Dartdoc bracketed references don't understand `super` parameters.[/-][+]Dartdoc bracketed references don't work for inherited members[/+]bwilkerson commentedon Aug 23, 2022
I don't know what
dart docdoes with that code, but the analyzer should match it as closely as possible, given the performance constraints it has to operate under.I think we want to walk up the superclass chain first and only look in interfaces when we can't find a member from a supertype. I believe that that's the behavior we use in other features, and it would be good to be consistent. I also think that that's the behavior we'd get from using
InheritanceManager3, which is probably the best way to implement such a lookup.DanTup commentedon Aug 23, 2022
I tested the example above, and it does appear to work:
I'll take a look, thanks!
[analyzer] Resolve comment references for inherited members
DanTup commentedon Aug 25, 2022
Fixed by dart-lang/sdk@857a0d2 (ships in the SDK, not a Dart extension update).