Skip to content

Trailing declarator docs semantics need to be revisited #371

@lizmat

Description

@lizmat

S26 states:

Declarator blocks that start with C<#=> attach to the declarator declared at the start of the line immediately before them.

Seems pretty clear cut, now doesn't it. However, the current implementation is way too lenient in attaching, and sometimes attaches to objects one might not expect. Some examples. Please note that all of these examples have been distilled from actual spectests! :-(

class A {
    has $.a; has $.b; #= trailing
}

So, does the trailing doc attach to $.a or $.b? It attaches to $.a!

sub six(Str $param1, Str $param2) {
#= trailing comment for six?
}

So does this attach to the sub six? Or to $param2. It attaches to the sub, whereas $param2 is the last object seen that can have declarator doc.

sub a { }
... many lines of code without declarable objects
#= still attaches to &a

The trailing declarator can be many lines after the object it attaches to, if there's nothing declarable inbetween. This violates S26.

Another example, where trailing docs are before the leading docs:

sub four {}
#| before five
#= after four
sub five {}

I think this should at least be a worry, as this may indicate a mixup on leading/trailing doc, or a copy-pasto.

And a more general issue, that could be considered a bug:

sub a {
#= foo bar
}

That actually attaches the trailing doc to sub a. But the object that lives in $=pod's is not complete: its WHEREFORE is Any, unless you call &a.WHY after which it will be correct. But that's not very useful for rakudoc renderers, as it won't be able to see to what the pod applies to.

I think we should have clearer rules on what the exact semantics are, and have more worries issued in situations where it would be unclear to which object a trailing doc should be attached to.

Metadata

Metadata

Assignees

No one assigned

    Labels

    languageChanges to the Raku Programming Language

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions