@@ -8951,6 +8951,25 @@ fn unassign_variable() {
89518951
89528952 let errors = analyze ( code) ;
89538953 assert ! ( errors. is_empty( ) ) ;
8954+
8955+ // With every arm folded away and no `default`, nothing drives `o` - reported
8956+ // as unassigned, not as an uncovered branch on always-false `if`s.
8957+ let code = r#"
8958+ module ModuleA (
8959+ o: output logic<4>,
8960+ ) {
8961+ always_comb {
8962+ for i in 0..4 {
8963+ switch {
8964+ i >: 10: o[i] = 1;
8965+ }
8966+ }
8967+ }
8968+ }
8969+ "# ;
8970+
8971+ let errors = analyze ( code) ;
8972+ assert ! ( matches!( errors[ 0 ] , AnalyzerError :: UnassignVariable { .. } ) ) ;
89548973}
89558974
89568975#[ test]
@@ -9981,6 +10000,72 @@ fn uncovered_branch() {
998110000
998210001 let errors = analyze ( code) ;
998310002 assert ! ( errors. is_empty( ) ) ;
10003+
10004+ // A compile-time-true `switch` arm makes the missing `default` unreachable.
10005+ let code = r#"
10006+ module ModuleA (
10007+ i_a: input logic ,
10008+ o : output logic<4>,
10009+ ) {
10010+ always_comb {
10011+ for i in 0..4 {
10012+ switch {
10013+ i_a : o[i] = 1;
10014+ i <: 4 : o[i] = 0;
10015+ }
10016+ }
10017+ }
10018+ }
10019+ "# ;
10020+
10021+ let errors = analyze ( code) ;
10022+ assert ! ( errors. is_empty( ) ) ;
10023+ }
10024+
10025+ #[ test]
10026+ fn switch_const_false_arm_body_unchecked ( ) {
10027+ // A dead arm's body is never converted, so conversion-time checks stop seeing
10028+ // it. That is the point here: unrolling the `for` puts this select out of range.
10029+ let code = r#"
10030+ module ModuleA (
10031+ o: output logic<4>,
10032+ ) {
10033+ always_comb {
10034+ for i in 0..4 {
10035+ switch {
10036+ i >: 3 : o[i + 1] = 1;
10037+ default: o[i] = 0;
10038+ }
10039+ }
10040+ }
10041+ }
10042+ "# ;
10043+
10044+ let errors = analyze ( code) ;
10045+ assert ! ( errors. is_empty( ) ) ;
10046+
10047+ // The same skip also hides condition-independent errors like a wrong argument
10048+ // count. `if` behaves this way too; pinned so `switch` is revisited with it.
10049+ let code = r#"
10050+ module ModuleA (
10051+ o: output logic<4>,
10052+ ) {
10053+ function f (a: input logic) -> logic {
10054+ return a;
10055+ }
10056+ always_comb {
10057+ for i in 0..4 {
10058+ switch {
10059+ i >: 10: o[i] = f(1, 2, 3);
10060+ default: o[i] = 0;
10061+ }
10062+ }
10063+ }
10064+ }
10065+ "# ;
10066+
10067+ let errors = analyze ( code) ;
10068+ assert ! ( errors. is_empty( ) ) ;
998410069}
998510070
998610071#[ test]
0 commit comments