Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type restrictions to Array#concat #1091

Closed
wants to merge 1 commit into from

Conversation

yui-knk
Copy link
Contributor

@yui-knk yui-knk commented Aug 2, 2015

To stop something

in ./src/array.cr:420: no overload matches 'Pointer(Int32)#value=' with types (String | Int32 | Char)
Overloads are:
 - Pointer(Int32)#value=(value : Int32)
Couldn't find overloads for these types:
 - Pointer(Int32)#value=(value : String)
 - Pointer(Int32)#value=(value : Char)

      buf.value = elem
          ^~~~~

but I still face these bug

a = [1, 2, 3]
a.concat(["4", 'e', 2])

# compile error
Using compiled compiler at .build/crystal
Error in crystal/one.cr:24: instantiating 'Array(Int32)#concat(Array((String | Int32 | Char)))'

      a.concat(["4", 'e', 2])
        ^~~~~~

in ./src/array.cr:414: instantiating 'Array((String | Int32 | Char))#each()'

    other.each do |elem|
          ^~~~

in ./src/array.cr:497: instantiating 'each_index()'

    each_index do |i|
    ^~~~~~~~~~

in ./src/array.cr:497: instantiating 'each_index()'

    each_index do |i|
    ^~~~~~~~~~

in ./src/array.cr:414: instantiating 'Array((String | Int32 | Char))#each()'

    other.each do |elem|
          ^~~~

in ./src/array.cr:420: no overload matches 'Pointer(Int32)#value=' with types (String | Int32 | Char)
Overloads are:
 - Pointer(Int32)#value=(value : Int32)
Couldn't find overloads for these types:
 - Pointer(Int32)#value=(value : String)
 - Pointer(Int32)#value=(value : Char)

      buf.value = elem
          ^~~~~

I can not find out why concat(other : Enumerable(T)) is called, sorry :(

@asterite
Copy link
Member

asterite commented Aug 2, 2015

@yui-knk I think that it enters Enumerable is a bug. I'll try to fix it before merging this. Thanks!

@asterite
Copy link
Member

It turns out this depends on resolving #1297 first.

@asterite
Copy link
Member

I'll close this for now. The compiler still rejects concatenating an array with non-compatible types. The error could definitely be improved, but until we define how we want variance to work I'll close this as we won't tackle it soon.

@asterite asterite closed this Mar 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants