Skip to content

Generic return type for closure returned from function doesn't work #13253

@lambdachad

Description

@lambdachad

V version: 0.2.4
OS: Arch Linux

What did you do?

fn closure<T>(input T) fn () T {
    return fn [input] () T {
        return input
    }
}

fn main() {
    closure(123)
}

What did you expect to see?
No error.

What did you see instead?

./bug.v:4:12: error: generic function declaration must specify generic type names, e.g. foo<T>
    2 | 
    3 | fn closure<T>(input T) fn () T {
    4 |     return fn [input] () T {
      |            ~~~~~~~~~~~~~~~~~
    5 |         return input
    6 |     }

I tried adding generic type name, but that resulted in this:

./bug.v:4:14: error: unexpected token `<`, expecting `(`
    2 | 
    3 | fn closure<T>(input T) fn () T {
    4 |     return fn<T> [input] () T {
      |              ^
    5 |         return input
    6 |     }

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions