Skip to content

Fix Kernel#p typing#73

Merged
soutaro merged 1 commit intoruby:masterfrom
pocke:p-type
Nov 10, 2019
Merged

Fix Kernel#p typing#73
soutaro merged 1 commit intoruby:masterfrom
pocke:p-type

Conversation

@pocke
Copy link
Member

@pocke pocke commented Nov 10, 2019

This pull request fixes Kernel#p type.
Currently the return value is typed as NilClass, but actually it returns the argument type.

But, I think this proposed type is not the best way. Because it is too loose for multiple arguments.

p 1 # => returns `1`, and the type is Integer
p 1, 2 # => returns `[1, 2]`, but the type is Array[untyped]

I'm not sure we can write the return value type. But I have a compromise idea with a limited number of arguments.

def p: [T] (T arg0) -> T
     | [T, U] (T arg0, U arg1) -> [T, U]
     | [T, U, V] (T arg0, U arg1, V arg2) -> [T, U, V]
     | [T, U, V, W] (T arg0, U arg1, V arg2, W arg3) -> [T, U, V, W]
     | [T, U, V, W, X] (T arg0, U arg1, V arg2, W arg3, X arg4) -> [T, U, V, W, X]
     | [T, U, V, W, X, Y] (T arg0, U arg1, V arg2, W arg3, X arg4, Y arg5) -> [T, U, V, W, X, Y]
     | [T, U, V, W, X, Y, Z] (T arg0, U arg1, V arg2, W arg3, X arg4, Y arg5, Z arg6) -> [T, U, V, W, X, Y, Z]
     | (*untyped arg0) -> Array[untyped]

It works correctly if the arguments are less than 8.

If you'd like the idea, I'll apply it to this pull request. If you have any idea to write the type with a more cool code, please tell me it!

Thanks.

@soutaro
Copy link
Member

soutaro commented Nov 10, 2019

I'm not sure if having expanded definitions makes sense. So, your definition looks ok!

@soutaro soutaro merged commit ba38873 into ruby:master Nov 10, 2019
@pocke pocke deleted the p-type branch November 11, 2019 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants