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

Assigning a variable to itself when defining that variablee #1049

Closed
GlenDC opened this issue Sep 6, 2015 · 5 comments
Closed

Assigning a variable to itself when defining that variablee #1049

GlenDC opened this issue Sep 6, 2015 · 5 comments

Comments

@GlenDC
Copy link

GlenDC commented Sep 6, 2015

Elm seems to not catch the issue in which a variable is defined using a self-asignment or a calculation that involves itself.

A modified version of the Hello World Example:

import Html exposing (text)

main =
  let x = x
  in text x

As you can see, this is a clear mistake, but the compiler doesn't seem to detect this. It's quite an annoying error as it's hard to debug such issues when finding in your code.

An even more rediculous example (based on the previous example) that compiles is:

 let x = y
      y = x
  in text y

It's the same kind of error, whereby you use a variable before it is defined.
Would be great if such code get's flagged as an error with a message such as "Error: Using variable 'x' before it is defined at Line ?"

@jvoigtlaender
Copy link
Contributor

I'm pretty certain this is already covered by other issues. Have you looked?

@GlenDC
Copy link
Author

GlenDC commented Sep 6, 2015

I looked with keywords such as variable and I only found stuff like variable-shadowing. This wasn't reported as far as I'm aware. I'm sorry if it was and you can mark it as duplicate in such case.

@jvoigtlaender
Copy link
Contributor

I was thinking about various issues with recursive definitions. The following one seems the most encompassing one at the moment: #873. At its bottom it lists several related ones.

Maybe your example adds some new aspect, so instead of closing the issue right away, maybe you can first look through the referenced ones to see whether it is already covered.

@mgold
Copy link
Contributor

mgold commented Sep 6, 2015

Yeah, it's a known issue. Even x = x at the top level creates a value of type a, which you can then use as any type and wreak havoc. Thanks for reporting.

@JoeyEremondi
Copy link
Contributor

I'm working on a fix for this, since it's related to DeadCode elimination. Please close this issue, since it's covered by #873 .

@evancz evancz closed this as completed Sep 7, 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
Development

No branches or pull requests

5 participants