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

Possible bug related to generics type resolution/matched #6732

Closed
zlash opened this issue Nov 12, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@zlash
Copy link

commented Nov 12, 2017

Hello,
I expect the following snippet to fail compilation, however it compiles correctly.
The .type.name expressions show different types on both echo calls when, as I understand, they should be refs to the same object.
I apologize in advance If it is not a bug and a misunderstanding of nim from my part

import typetraits

type
    TT[T] = ref object of RootObj
        val: T
    CB[T] = proc (v: T): void

proc testGeneric[T](val: TT[T], cb: CB[T]): void =
    echo val.type.name
    echo $val.val


var tt = new(TT[seq[string]])
echo tt.type.name
tt.testGeneric( proc (v: int): void =
    echo $v )
@zah

This comment has been minimized.

Copy link
Member

commented Nov 13, 2017

The code is perfectly fine and the output with the latest compiler from the devel branch is:

TT[seq[string]]
TT[seq[string]]

What was the output you got?

@andreaferretti

This comment has been minimized.

Copy link
Collaborator

commented Nov 13, 2017

I think the problem is that this example should not compile. The two T in TT[T] and CB[T] are different: from TT the compiler can infer T = seq[string], but from CB it can deduce T = int.

@zah zah self-assigned this Nov 13, 2017

@zah zah added the Generics label Nov 13, 2017

@zah

This comment has been minimized.

Copy link
Member

commented Nov 13, 2017

Ah, I see. This should be an error indeed.

@zlash

This comment has been minimized.

Copy link
Author

commented Nov 13, 2017

Exactly, as @andreaferretti said.
FYI, i'm running Version 0.17.2 (2017-09-08) and the output of the snippet is:

TT[seq[string]]
TT[system.int]
0

@Araq Araq added the High Priority label Jan 23, 2019

Araq added a commit that referenced this issue May 14, 2019

@Araq Araq closed this in 95f8ed0 May 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.