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

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

Closed
horasal opened this issue Feb 16, 2015 · 5 comments
Closed

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

horasal opened this issue Feb 16, 2015 · 5 comments
Milestone

Comments

@horasal
Copy link
Contributor

horasal 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
Copy link
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
Copy link
Collaborator

Making progress

screen shot 2015-07-08 at 09 47 25

@vendethiel
Copy link

Is this going inside some test/ folder?

@fasterthanlime
Copy link
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
Copy link

Great to hear 👍

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

No branches or pull requests

3 participants