Skip to content

[BUG] 'forward' return type deduction #1404

Open
@ArakawaHenri

Description

@ArakawaHenri

Describe the bug

For the simplest functions that return arguments directly and do not specify anonymous return value, the deduction of the return value type might be problematic.

To Reproduce

These would compile normally:

case 1:

nontem: (a: int, b: int) = a+b;

main:() = {
  x:=1;
  y:=nontem(x, x);
  printf("%d\n", y);
}

case 2:

tem: <T: type> (a: T, b: T) = a+b;

main:() = {
  x:=1;
  y:=tem<int>(x ,x);
  printf("%d\n", y);
}

case 3:

nontem: (a: int) -> int = a;

main:() = {
  x:=1;
  y:=nontem(x);
  printf("%d\n", y);
}

case 4:

tem: <T: type> (a: T) -> T = a;

main:() = {
  x:=1;
  y:=tem<int>(x);
  printf("%d\n", y);
}

case 5:

nontem: (a: int) -> _ = a;

main:() = {
  x:=1;
  y:=nontem(x);
  printf("%d\n", y);
}

case 6:

tem: <T: type> (a: T) -> _ = a;

main:() = {
  x:=1;
  y:=tem<int>(x);
  printf("%d\n", y);
}

These generate error: a 'forward' return type cannot return an 'in', 'copy', or 'move' parameter at compile time:

case 7:

tem: <T: type> (a: T) = a;

main:() = {
  x:=1;
  y:=tem<int>(x);
  printf("%d\n", y);
}

case 8:

nontem: (a: int) = a;

main:() = {
  x:=1;
  y:=nontem(x);
  printf("%d\n", y);
}

I am not an expert. I realise that this may have been intentional when the grammar was designed, or it may not have been considered in the rare cases. I'm wondering if the rules should be made clearer for these few cases?

Also, I know that the current syntax explicitly states that the type declaration of retrun value cannot be omitted for complex function bodies wrapped in curly braces. And I understand that this may be because for complex logic and processes, deduction of the type of the return value and checking the consistency of the type of the return value from different branches is complex. But is this rule open for discussion? Since -> _ is still acceptable for this kind of functions, there might be plan or it might be possible to implement fully automatic return value type deduction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions