Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

resolve: a non-binding use of a global may precede its binding #123

Merged
merged 1 commit into from
Aug 22, 2018

Conversation

alandonovan
Copy link
Contributor

@alandonovan alandonovan commented Aug 22, 2018

According to the agreed Skylark spec, and unlike the Python semantics currently implemented, this program should yield a dynamic error:

 print(len) # dynamic error: uninitialized global
 len = 1
 print(len)

We now defer the resolution of forward-uses at top level until the end of the module, just as we do for locals.

Fixes #116

@alandonovan alandonovan requested a review from jayconrod August 22, 2018 20:44
According to the agreed Skylark spec, and unlike the Python semantics
currently implemented, this program should yield a dynamic error:

 print(len) # dynamic error: uninitialized global
 len = 1
 print(len)

We now defer the resolution of forward-uses at top level until the end
of the module, just as we do for locals.

Fixes #116

Change-Id: I802bded5d50c45702a4da08c40144574cdf4296a
@@ -1140,6 +1140,7 @@ nested in any order, to any depth.
If name is bound anywhere within a block, all uses of the name within
the block are treated as references to that binding, even uses that
appear before the binding.
This is true even in the module block, unlike Python.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why continue to maintain this document instead of pointing to https://docs.bazel.build/versions/master/skylark/spec.html? There should be one true spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This document accurately describes the language implemented by Skylark-in-Go. A single true spec would be nice, but for the Bazel team, support for uses of Skylark other than Bazel does not appear to be a priority right now, so Skylark-in-Java lags behind some features that we agreed upon such as support for the kinds of numbers encountered in protocol buffers, separation of x.f() calls into two steps y = x.f; y(), the string methods elem_ords, codepoints, and codepoint_ords, and so on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My recommendation is to point to https://github.com/bazelbuild/starlark/blob/master/spec.md
and document only the differences. Hopefully we can reduce the list of differences over time.

@alandonovan alandonovan merged commit 4956ce9 into master Aug 22, 2018
alandonovan pushed a commit to google/starlark-go that referenced this pull request Nov 21, 2018
This change causes the AllowGlobalReassign flag (used for legacy Bazel
semantics) to also allow use of predeclared names prior to a global
binding of the same name, as in:

   print(len); len=1; print(len)

This effectively reverses github.com/google/skylark/pull/123 behind an option.

See github.com/google/skylark/issues/116 for discussion.

Change-Id: If514136aaa705154379f445e3b1b287fcb1fdfd6
alandonovan pushed a commit to google/starlark-go that referenced this pull request Nov 26, 2018
This change causes the AllowGlobalReassign flag (used for legacy Bazel
semantics) to also allow use of predeclared names prior to a global
binding of the same name, as in:

   print(len); len=1; print(len)

This effectively reverses github.com/google/skylark/pull/123 behind an option.

See github.com/google/skylark/issues/116 for discussion.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants