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 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

@fasterthanlime fasterthanlime commented Jul 8, 2015

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

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

Same goes for tuple declarations.

Loading

@fasterthanlime
Copy link
Collaborator

@fasterthanlime fasterthanlime commented Jul 8, 2015

Making progress

screen shot 2015-07-08 at 09 47 25

Loading

@vendethiel
Copy link

@vendethiel vendethiel commented Jul 8, 2015

Is this going inside some test/ folder?

Loading

@fasterthanlime
Copy link
Collaborator

@fasterthanlime fasterthanlime commented Jul 8, 2015

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.

Loading

@vendethiel
Copy link

@vendethiel vendethiel commented Jul 8, 2015

Great to hear 👍

Loading

@fasterthanlime fasterthanlime added this to the 0.9.10 milestone Jul 10, 2015
@fasterthanlime fasterthanlime added this to the 0.9.10 milestone Jul 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants