Sitelet https://github.com/starkware-libs/cairo/commit/e2c8f337a5a2ddf5d089be8be5dec4d1aad12aa3
Skip to content

Commit e2c8f33

Browse files
test(semantic): add test for invalid patterns on Span value (#9839)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2304744 commit e2c8f33

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

  • crates/cairo-lang-semantic/src/expr/test_data

‎crates/cairo-lang-semantic/src/expr/test_data/pattern‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,61 @@ foo
439439
//! > module_code
440440

441441
//! > expected_diagnostics
442+
443+
//! > ==========================================================================
444+
445+
//! > Test invalid patterns on Span value.
446+
447+
//! > test_runner_name
448+
test_function_diagnostics(expect_diagnostics: true)
449+
450+
//! > function_code
451+
fn foo(s: Span<u32>) -> u32 {
452+
match s {
453+
[a, b] => *a + *b,
454+
5 => 0,
455+
(a, b) => *a + *b,
456+
Some(a) => *a,
457+
}
458+
}
459+
460+
//! > function_name
461+
foo
462+
463+
//! > module_code
464+
465+
//! > expected_diagnostics
466+
error[E2103]: Mismatched types: pattern cannot match against type "core::array::Span::<core::integer::u32>".
467+
--> lib.cairo:5:9
468+
(a, b) => *a + *b,
469+
^^^^^^
470+
471+
error[E2135]: Type `<missing>` cannot be dereferenced
472+
--> lib.cairo:5:19
473+
(a, b) => *a + *b,
474+
^
475+
476+
error[E2135]: Type `<missing>` cannot be dereferenced
477+
--> lib.cairo:5:24
478+
(a, b) => *a + *b,
479+
^
480+
481+
error[E2103]: Mismatched types: pattern cannot match against type "core::array::Span::<core::integer::u32>".
482+
--> lib.cairo:6:9
483+
Some(a) => *a,
484+
^^^^^^^
485+
486+
error[E0006]: Identifier not found.
487+
--> lib.cairo:6:21
488+
Some(a) => *a,
489+
^
490+
491+
error[E2135]: Type `<missing>` cannot be dereferenced
492+
--> lib.cairo:6:20
493+
Some(a) => *a,
494+
^
495+
496+
error[E2311]: Mismatched types. The type `core::array::Span::<core::integer::u32>` cannot be created from a numeric literal.
497+
--> lib.cairo:4:9
498+
5 => 0,
499+
^

0 commit comments

Comments
 (0)