Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fbc2d570 authored by Martin Geisler's avatar Martin Geisler
Browse files

pdl: remove “checksum start precedes checksum field” lint

This lint is wrong, it is okay for the checksum start to start before
the checksum field itself. We have real files in the wild that uses
this construct, such as l2cap_packets.pdl.

Bug: 238865051
Test: atest pdl_inline_tests
Change-Id: I5d709a0fefdbdede704f799b46a20f523459d604
parent 37a86072
Loading
Loading
Loading
Loading
+19 −14
Original line number Diff line number Diff line
@@ -687,20 +687,6 @@ fn lint_checksum(
                // is checked.
                None => (),
            };
            // Check declaration order of checksum field.
            match field_decl.and_then(|f| f.0.first()) {
                Some(decl) if decl.loc().start > checksum_loc.start => result.push(
                    Diagnostic::error()
                        .with_message("invalid checksum start declaration")
                        .with_labels(vec![
                            checksum_loc
                                .primary()
                                .with_message("checksum start precedes checksum field"),
                            decl.loc().secondary().with_message("checksum field is declared here"),
                        ]),
                ),
                _ => (),
            }
        }
        Some(field) => result.push(
            Diagnostic::error()
@@ -1290,4 +1276,23 @@ mod test {
        let result = grammar.lint();
        assert!(!result.diagnostics.is_empty());
    }

    #[test]
    fn test_packet_checksum_start() {
        let mut db = SourceDatabase::new();
        let grammar = grammar!(
            &mut db,
            r#"
              little_endian_packets
              checksum Checksum : 8 "Checksum"
              packet P {
                  _checksum_start_(crc),
                  a: 16,
                  crc: Checksum,
              }
            "#
        );
        let result = grammar.lint();
        assert!(dbg!(result.diagnostics).is_empty());
    }
}