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

Invalid code successfully typechecks #917

Closed
fallen-icarus opened this issue Apr 30, 2024 · 2 comments
Closed

Invalid code successfully typechecks #917

fallen-icarus opened this issue Apr 30, 2024 · 2 comments
Labels
bug Something isn't working typechecking Types and inference

Comments

@fallen-icarus
Copy link

What Git revision are you using?

aiken v1.0.26-alpha+unknown

Describe what the problem is?

The following code typechecks, but it shouldn't.

use aiken/dict.{Dict}
use aiken/list
use aiken/transaction/value.{Value, PolicyId, AssetName}

pub fn extract_offer_quantity(val: Value) -> (Int,Int,Bool) {
  let foo = fn(_x: (PolicyId,Dict<AssetName,Int>), acc: (Int,Int,Bool)) {
    let (offer_quantity, ada_quantity, has_proper_beacons) = acc

    (offer_quantity, ada_quantity) // This is wrong. It is missing the Bool.
  }

  list.foldl(
    value.to_dict(val) |> dict.to_list(_), 
    (0,0,False), 
    foo
  )
}

The inner foo function is supposed to return (Int,Int,Bool) when used with list.foldl, but in the above code, it returns (Int,Int). aiken check just gives a warning that has_proper_beacons is unused. If I change it to return (offer_quantity, ada_quantity, has_proper_beacons), aiken check successfully typechecks again, but this time without the warning.

What should be the expected behavior?

The above code could should not typecheck.

@KtorZ KtorZ added the typechecking Types and inference label May 1, 2024
@KtorZ
Copy link
Member

KtorZ commented May 1, 2024

Oof... That's bad. Seems like this broke somewhere between v1.0.24 and v1.0.25. I'll do a quick git bisect to identify the issue. And seems like we have a hole in our test coverage.

Thanks for reporting @fallen-icarus.

@KtorZ KtorZ added the bug Something isn't working label May 1, 2024
@KtorZ
Copy link
Member

KtorZ commented May 1, 2024

The regression has been introduced in: ed9f5c6

Probably in the PartialEq instance:

                    name == name2
                        && module == module2
                        && public == public2
                        && args.iter().zip(args2).all(|(left, right)| left == right)

The zip here is likely throwing all exceeding arguments between two sets. So it's only validating arguments up to the shortest length. In your example, there's (Int, Int) being checked against (Int, Int, Bool), so it passes 🤦.

@KtorZ KtorZ closed this as completed in 925a11b May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typechecking Types and inference
Projects
Status: 🚀 Released
Development

No branches or pull requests

2 participants