Disallow shadowing? #86

Closed
opened 2024-06-17 20:31:27 +00:00 by scott · 4 comments
Owner
No description provided.
Author
Owner

Is the correct?

Technically, what happens when a function body is a block?

Well, a block is a new scope. So when the function body is a new block, it's a child scope, with the parent scope being the scope for the function body. That means that we would have to special-case the "function body is a block" situation.

I'm disinclined to special-case things.

@matt What do you think? Should the following be allowed?

fn foo (bar) -> {
  let bar = inc (bar) & rebinding of parameter name
}

You wouldn't be able to do

fn foo (bar) -> let bar = bar

But actually, this wouldn't even parse, because function bodies actually must be non-binding expressions.

So the question is, is a block that's a function body different from other kinds of blocks, so people can't re-bind function parameter names?

Is the correct? Technically, what happens when a function body is a block? Well, a block is a new scope. So when the function body is a new block, it's a child scope, with the parent scope being the scope for the function body. That means that we would have to special-case the "function body is a block" situation. I'm disinclined to special-case things. @matt What do you think? Should the following be allowed? ``` fn foo (bar) -> { let bar = inc (bar) & rebinding of parameter name } ``` You wouldn't be able to do ``` fn foo (bar) -> let bar = bar ``` But actually, this wouldn't even parse, because function bodies actually must be non-binding expressions. So the question is, is a block that's a function body different from other kinds of blocks, so people can't re-bind function parameter names?
scott changed title from Validator should not allow re-binding of function parameters to Disallow shadowing? 2024-06-21 14:35:32 +00:00
Author
Owner

Actually, the conversation leads us to think we should disallow shadowing.

One question is whether we allow shadowing of names bound in Prelude. The first thought is that yes, you can shadow Prelude, but scripts may not shadow bindings they introduce.

Actually, the conversation leads us to think we should disallow shadowing. One question is whether we allow shadowing of names bound in Prelude. The first thought is that yes, you can shadow Prelude, but scripts may not shadow bindings they introduce.
scott added the
accepted
enhancement
labels 2024-07-03 00:18:33 +00:00
Author
Owner

Validator now disallows shadowing of any name in any context. Next up: develop logic in validator to only check names that are explicitly bound in a script, and not names that are in Prelude.

Validator now disallows shadowing of any name in any context. Next up: develop logic in validator to only check names that are explicitly bound in a script, and not names that are in Prelude.
Author
Owner

Done in 98421a9215

Done in https://alea.ludus.dev/twc/ludus/commit/98421a92154778d521afb44ceedc54e04f6b76dc
scott closed this issue 2024-07-20 17:51:50 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: twc/ludus#86
No description provided.