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

Impure range expressions #1397

Closed
robinsierra opened this issue Apr 17, 2019 · 1 comment · Fixed by #1424
Closed

Impure range expressions #1397

robinsierra opened this issue Apr 17, 2019 · 1 comment · Fixed by #1424
Labels
bug Bug that shouldn't change language semantics when fixed.

Comments

@robinsierra
Copy link

Version Information

  • vyper Version: 0.1.0b9
  • Tested with Remix IDE

Currently Vyper allows range expressions of the form range(x, x + n) where n is a constant. A weird case happens when x is impure:

glob: int128

@public
def foo() -> int128:
	self.glob += 1
	return 5


@public
def bar():
	for i in range(self.foo(), self.foo() + 1):
		pass

Even though the range expression contains two calls to self.foo() it is only executed once, which feels very unintuitive at best. In general, it would be nice to have some documentation for loops/range expressions (especially if this is the intended behavior).

@jacqueswww
Copy link
Contributor

jacqueswww commented May 2, 2019

I agree, I don't think this should be allowed at all, ie. functions called in range() have to be @constant.

@jacqueswww jacqueswww added the bug Bug that shouldn't change language semantics when fixed. label May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that shouldn't change language semantics when fixed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants