Variables declared in tuple may conflict with function parameters. #863

Closed
zhaihj opened this Issue Feb 16, 2015 · 5 comments

Projects

None yet

3 participants

@zhaihj
Contributor
zhaihj commented Feb 16, 2015

When trying to compile something like this:

foo: func(i: Int) -> Int{
    (a, i) := ("test", 2)

    i
}

rock generates:

lang_Numbers__Int tuple__foo(lang_Numbers__Int i) {
    #line 2 "/home/housezet/complier/bug/tuple.ooc"
    lang_String__String* a = __tuple_strLit1;
    #line 2 "/home/housezet/complier/bug/tuple.ooc"
    lang_Numbers__Int i = 2;
    #line 4 "/home/housezet/complier/bug/tuple.ooc"
    return i;
}

and finally:

INSERT$ rock tuple                    
/home/housezet/complier/bug/tuple.ooc: In function ‘tuple__foo’:
/home/housezet/complier/bug/tuple.ooc:2:23: error: ‘i’ redeclared as different kind of symbol
     (a, i) := ("test", 2)
                       ^
rock_tmp/ooc/tuple/tuple.c:43:48: note: previous definition of ‘i’ was here
 lang_Numbers__Int tuple__foo(lang_Numbers__Int i) {
                                                ^
/home/housezet/complier/bug/tuple.ooc:2:26: warning: unused variable ‘a’ [-Wunused-variable]
     (a, i) := ("test", 2)
                          ^
C compiler failed on module tuple from tuple, bailing out

[FAIL]

but this works even though it may not output correctly:

i: Int = 1
(a, i) := (1, 2)
i toString() println()

This prints 1 instead 2 beacuse a new variable tuple_i is generated (but can never be used, of course).

@fasterthanlime
Collaborator

So, the correct behaviour is to disallow such a declaration.

foo: func (i: Int) {
  i := 4 // rock should err
}

Same goes for tuple declarations.

@fasterthanlime
Collaborator

Making progress

screen shot 2015-07-08 at 09 47 25

@vendethiel

Is this going inside some test/ folder?

@fasterthanlime
Collaborator

Even better:

screen shot 2015-07-08 at 10 01 51

@vendethiel Well, it should. Messed it up for the previous few fixes, will do it for this one.

@vendethiel

Great to hear 👍

@fasterthanlime fasterthanlime modified the milestone: 0.9.10 Jul 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment