Skip to content

Sugar anonymous procedure and procedure type fails on identity function #18447

@arkanoid87

Description

@arkanoid87

Identity function fails to compile when using sugar function types.
Seem related to how "auto" type works with sugar function types.

Example

import sugar, macros
let identity: int -> int = x => x

By rewriting the => macro, seems that the "auto" type of function argument is not smart enough

This fails to compile

import sugar, macros
let identity: int -> int = proc(x: auto): int = x

This compiles successfully

import sugar, macros
let identity: int -> int = proc(x: int): auto = x

Current Output

Error: A nested proc can have generic parameters only when it is used as an operand to another routine and the types of the generic paramers can be inferred from the expected signature.

Expected Output

compilation successfull

Version

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-06-01
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: c0e8199acc9f49caa36bae34d103600d112b66f3
active boot switches: -d:release

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions