erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.69k stars 55 forks source link

Cannnot specify and recognize return value types of anonymous function #343

Open GreasySlug opened 1 year ago

GreasySlug commented 1 year ago

Describe the bug?

Error occurs when return value is specified of anonymous function

edit: the anonymous function operator cannot recognize the return type.

Reproducible code

f = (x, y) -> x + y
g = (x: Int, y) -> x + y
h = (x, y: Int) -> x + y
i = (x, y): Int -> x + y
j = (x: Int, y: Int): Int -> x + y

Expected result

No error

Actual result

::f =
    (x, y, , ) ->
        `+`:
            ::x
            ::y
::g =
    (x: ::Int, y, , ) ->
        `+`:
            ::x
            ::y
::h =
    (x, y: ::Int, , ) ->
        `+`:
            ::x
            ::y
Error[#0393]: File .\examples\for.er, line 4, 

4 | i = (x, y): Int -> x + y
  :                      ---

SyntaxError: invalid syntax

Error[#0393]: File .\examples\for.er, line 5,

5 | j = (x: Int, y: Int): Int -> x + y
  :                                ---

SyntaxError: invalid syntax

Additional context

No response

Erg version

Erg 0.6.2-nightly.0

Python version

Python3.11.x

OS

Windows 10

mtshiba commented 1 year ago

This is not a bug, but an associative order of anonymous function operators.

i = (x, y): Int -> x + y

The above code is interpreted as follows.

i = (x, y): (Int -> x + y)

I'm aware that this is not natural, but I didn't fix it because I could just wrap it in ().

mtshiba commented 1 year ago

Ah, before that, it seems that the anonymous function operator cannot recognize the return type.