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

bug: Alias for Option Causes "Invalid path" Error in match #6909

Open
0xNeshi opened this issue Dec 22, 2024 · 1 comment
Open

bug: Alias for Option Causes "Invalid path" Error in match #6909

0xNeshi opened this issue Dec 22, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@0xNeshi
Copy link

0xNeshi commented Dec 22, 2024

Bug Report

Cairo version:

scarb 2.9.2+nightly-2024-12-22 (29eda693a 2024-12-22)
cairo: 2.9.2 (b356014ef)
sierra: 1.6.0

Current behavior:

When setting an alias for Option, like:

type OptAlias<T> = Option<T>;

One is able to assign a value of this alias type using the Alias name like:

let opt_alias: OptAlias<u32> = OptAlias::None;

But matching against this alias using the alias name fails with "Invalid Path":

    let opt_alias: OptAlias<u32> = OptAlias::None;
    match opt_alias {
        OptAlias::None => println!("opt_alias is None"), // Error: Invalid path.
        OptAlias::Some(val) => println!("opt_alias is Some({val})"), // Error: Invalid path.
    }

Instead, one has to use Option directly:

    let opt_alias: OptAlias<u32> = OptAlias::None;
    match opt_alias {
        Option::None => println!("opt_alias is None"), // works
        Option::Some(val) => println!("opt_alias is Some({val})"), // works
    }

Expected behavior:

One should be able to use alias name in the match.

Steps to reproduce:

  • create new project
  • open lib.cairo
  • copy/paste the below related code into it
  • compile
  • expected: compile successful
  • actual: compilation fails with "Invalid path."

Related code:

type OptAliasU32 = Option<u32>;

type OptAlias<T> = Option<T>;

fn main() {
    let opt: Option<u32> = Option::None;
    match opt {
        Option::None => println!("opt is None"),
        Option::Some(val) => println!("opt is Some({val})"),
    }

    let opt_alias: OptAliasU32 = OptAliasU32::None;
    match opt_alias {
        Option::None => println!("opt_alias is None"), // works
        Option::Some(val) => println!("opt_alias is Some({val})"), // works
    }

    let opt_alias: OptAlias<u32> = OptAlias::None;
    match opt_alias {
        Option::None => println!("opt_alias is None"), // works
        Option::Some(val) => println!("opt_alias is Some({val})"), // works
    }

    let opt_alias: OptAliasU32 = OptAliasU32::None;
    match opt_alias {
        OptAliasU32::None => println!("opt_alias is None"), // Invalid path.
        OptAliasU32::Some(val) => println!("opt_alias is Some({val})"), // Invalid path.
    }

    let opt_alias: OptAlias<u32> = OptAlias::None;
    match opt_alias {
        OptAlias::None => println!("opt_alias is None"), // Invalid path.
        OptAlias::Some(val) => println!("opt_alias is Some({val})"), // Invalid path.
    }
}

Other information:

@0xNeshi 0xNeshi added the bug Something isn't working label Dec 22, 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
Projects
None yet
Development

No branches or pull requests

3 participants
@0xNeshi @dean-starkware and others