aiken-lang / aiken

A modern smart contract platform for Cardano
https://aiken-lang.org
Apache License 2.0
396 stars 82 forks source link

typecheck permitting variables not in (hygenic) scope #941

Closed waalge closed 2 months ago

waalge commented 2 months ago

What Git revision are you using?

v1.0.26-alpha+6d7b851

What operating system are you using, and which version?

nixos

Describe what the problem is?

pub fn a(x: Int) {
  b(x)
}

fn b(y: Int) {
  trace cbor.diagnostic((x, y))
  x + y
}

This type checks and causes a build to panic.

crates/uplc/src/optimize/shrinker.rs:960:67

       called `Result::unwrap()` on an `Err` value: FreeUnique(Name { text: "x", unique: Unique(6) })

Found when the LSP invited me to use a variable not in the scope of the function, but is where function is invoked, which confused me.

What should be the expected behavior?

Typecheck says this is illegal

KtorZ commented 2 months ago

Hmm. Looks like we've introduced a regression with the scope in https://github.com/aiken-lang/aiken/pull/922. I know the problem. Good thing we haven't released that version yet 😶 ...