Skip to content

Improve error message when partial has two return statements #11708

Open
@jmooring

Description

@jmooring

I know the return statement returns immediately regardless of conditional blocks, and that's fine. And I know the partial construct below is incorrect, and that's fine too.

The problem is that sometimes the error message is unexpected.

layouts/partials/is-even.html

{{ if (math.ModBool . 2) }}
  {{ return true }}
{{ else }}
  {{ return false }}
{{ end }}

layouts/_default/single.html

{{ if partial "is-even.html" 3 }}
  even
{{ else }}
  odd
{{ end }}

The current error message is:

executing "partials/foo.html" at <return>: wrong number of args for return: want 0 got 1

But if I call it with an even number, no errors:

{{ if partial "is-even.html" 4 }}
  even
{{ else }}
  odd
{{ end }}

The unexpected error message isn't anything new... same results with v0.55.0, where the return statement was introduced.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions