soutaro / rbs-inline

Inline RBS type declaration
MIT License
231 stars 7 forks source link

Ignoring overloads after the first in method comments #36

Closed euglena1215 closed 4 months ago

euglena1215 commented 4 months ago

Description

When using #:: comments to express method overloads, everything after the first | is ignored.

Steps to Reproduce

Run rbs-inline on the following program:

#:: (String) -> String | (Integer) -> Integer
def foo(x)
  x
end

Expected Result

The following should be generated:

#:: (String) -> String | (Integer) -> Integer 
def foo: (String) -> String | (Integer) -> Integer

Actual Result

Everything after the first | is ignored, resulting in:

#:: (String) -> String | (Integer) -> Integer 
def foo: (String) -> String

Environment

soutaro commented 4 months ago

The syntax accepts only one overload. So, having another overload after the | token doesn't work.

ParadoxV5 commented 4 months ago

Is this the current way to write overloads?

#:: (String) -> String
#:: (Integer) -> Integer

Perhaps OP’s expectation is more explicit?

#:: (String) -> String
# | (Integer) -> Integer
soutaro commented 4 months ago

Hmm... Yeah, it's possible.

euglena1215 commented 4 months ago

Oh, thank you very much. It seems to work as expected with the following.

#:: (String) -> String
#:: (Integer) -> Integer

I also found the following on the Wiki:

Having multiple #:: syntax generates method definition with overloads.

My issue was not so much a syntax problem, but rather that I felt rbs-inline could not express overloads. I will close this issue now that I know I was mistaken.

Thank you for your comments!