Draco-lang / Language-suggestions

Collecting ideas for a new .NET language that could replace C#
75 stars 5 forks source link

Make calling a method with an Union Type dispatch to the correct overload. #129

Open Kuinox opened 1 year ago

Kuinox commented 1 year ago

This is basically a syntaxic sugar to dispatch an union type to the correct overload if the method overloads cover all the union types. This would make the following possible:

public ToJSON(a: Foo): string {}
public ToJSON(a: Bar): string {}
public ToJSON(a: int): string {}

public string Process(arg: Foo|Bar|int)
{
  ToJson(arg);
}