Skip to content

Formatter failure with long line with macros #2492

@matlupi

Description

@matlupi

Test case

Minimum reproducible test case

$ verible-verilog-format --flagfile=.rules.verible_format test.sv
class dut_sc_checker extends sc_uvc_checker;
  `uvm_component_utils(dut_sc_checker)
  function new(string name = "dut_sc_checker", uvm_component parent);
    super.new(name, parent);
  endfunction
  function bit check_status(sc_uvc_sequence_item req);
    bit error = 1'b0;
    error |= condition(!req.m_status[ERR_SINGLECHIP_BYPASS], "SC_STS_NOTTODUT_NO_ERR_SINGLECHIP_BYPASS", $sformatf("Status bit is not set for transaction not directed to DUT\n%s", req.sprint()), `uvm_file, `uvm_line);
    return error;
  endfunction
endclass

Include any options or configuration used.

$ cat .rules.verible_format
--failsafe_success=false
--inplace
--line_break_penalty=8
--column_limit=200
--over_column_limit_penalty=100
--named_port_alignment=flush-left

Actual output of the command

$ verible-verilog-format --flagfile=.rules.verible_format test.sv
test.sv: Formatted output is lexically different from the input.    Please file a bug.  Details:
Mismatched token enums.  got: (MacroIdentifier) (#296: "`uvm_line") vs. (MacroIdItem) (#298: "`uvm_line")
First mismatched token [73]: (MacroIdentifier) (#296: "`uvm_line") vs. (MacroIdItem) (#298: "`uvm_line")
; problematic formatter output is
class dut_sc_checker extends sc_uvc_checker;
  `uvm_component_utils(dut_sc_checker)
  function new(string name = "dut_sc_checker", uvm_component parent);
    super.new(name, parent);
  endfunction
  function bit check_status(sc_uvc_sequence_item req);
    bit error = 1'b0;
    error |= condition(
        !req.m_status[ERR_SINGLECHIP_BYPASS], "SC_STS_NOTTODUT_NO_ERR_SINGLECHIP_BYPASS", $sformatf("Status bit is not set for transaction not directed to DUT\n%s", req.sprint()), `uvm_file, `uvm_line
    );
    return error;
  endfunction
endclass
<<EOF>>

Include any possible diagnostic messages from the formatter.

  • The line which is problematic seems to be this one, shortening it, results in the formatter passing.
error |= condition(!req.m_status[ERR_SINGLECHIP_BYPASS], "SC_STS_NOTTODUT_NO_ERR_SINGLECHIP_BYPASS", $sformatf("Status bit is not set for transaction not directed to DUT\n%s", req.sprint()), `uvm_file, `uvm_line);
  • verible versions affected
$ verible-verilog-format -version
Version	v0.0-4051-g9fdb4057
Commit-Timestamp	2025-12-22T08:55:10Z
Built	2025-12-22T08:59:31Z

and

$ verible-verilog-format -version
Version	v0.0-4023-gc1271a00
Commit-Timestamp	2025-08-29T09:25:59Z
Built	2025-08-29T09:28:29Z
  • In previous issues of this kind, users were asked to produce a syntax tree dump
Parse Tree:
Node @0 (tag: kDescriptionList) {
  Node @0 (tag: kClassDeclaration) {
    Node @0 (tag: kClassHeader) {
      Leaf @1 (#"class" @0-5: "class")
      Leaf @3 (#SymbolIdentifier @6-20: "dut_sc_checker")
      Node @5 (tag: kExtendsList) {
        Leaf @0 (#"extends" @21-28: "extends")
        Node @1 (tag: kUnqualifiedId) {
          Leaf @0 (#SymbolIdentifier @29-43: "sc_uvc_checker")
        }
      }
      Leaf @7 (#';' @43-44: ";")
    }
    Node @1 (tag: kClassItems) {
      Node @0 (tag: kMacroCall) {
        Leaf @0 (#MacroCallId @47-67: "`uvm_component_utils")
        Node @1 (tag: kParenGroup) {
          Leaf @0 (#'(' @67-68: "(")
          Node @1 (tag: kMacroArgList) {
            Node @0 (tag: kExpression) {
              Node @0 (tag: kFunctionCall) {
                Node @0 (tag: kReference) {
                  Node @0 (tag: kLocalRoot) {
                    Node @0 (tag: kUnqualifiedId) {
                      Leaf @0 (#SymbolIdentifier @68-82: "dut_sc_checker")
                    }
                  }
                }
              }
            }
          }
          Leaf @2 (#MacroCallCloseToEndLine @82-83: ")")
        }
      }
      Node @1 (tag: kClassConstructor) {
        Node @1 (tag: kClassConstructorPrototype) {
          Leaf @0 (#"function" @86-94: "function")
          Leaf @1 (#"new" @95-98: "new")
          Node @2 (tag: kParenGroup) {
            Leaf @0 (#'(' @98-99: "(")
            Node @1 (tag: kPortList) {
              Node @0 (tag: kPortItem) {
                Node @1 (tag: kDataTypeImplicitBasicIdDimensions) {
                  Node @0 (tag: kDataType) {
                    Node @1 (tag: kDataTypePrimitive) {
                      Leaf @0 (#"string" @99-105: "string")
                    }
                    Node @3 (tag: kPackedDimensions) {
                    }
                  }
                  Node @1 (tag: kUnqualifiedId) {
                    Leaf @0 (#SymbolIdentifier @106-110: "name")
                  }
                  Node @2 (tag: kUnpackedDimensions) {
                  }
                }
                Node @2 (tag: kTrailingAssign) {
                  Leaf @0 (#'=' @111-112: "=")
                  Node @1 (tag: kExpression) {
                    Leaf @0 (#TK_StringLiteral @113-129: "\"dut_sc_checker\"")
                  }
                }
              }
              Leaf @1 (#',' @129-130: ",")
              Node @2 (tag: kPortItem) {
                Node @1 (tag: kDataTypeImplicitBasicIdDimensions) {
                  Node @0 (tag: kDataType) {
                    Node @1 (tag: kLocalRoot) {
                      Node @0 (tag: kUnqualifiedId) {
                        Leaf @0 (#SymbolIdentifier @131-144: "uvm_component")
                      }
                    }
                    Node @3 (tag: kPackedDimensions) {
                    }
                  }
                  Node @1 (tag: kUnqualifiedId) {
                    Leaf @0 (#SymbolIdentifier @145-151: "parent")
                  }
                  Node @2 (tag: kUnpackedDimensions) {
                  }
                }
              }
            }
            Leaf @2 (#')' @151-152: ")")
          }
          Leaf @3 (#';' @152-153: ";")
        }
        Node @2 (tag: kStatementList) {
          Node @0 (tag: kStatement) {
            Node @0 (tag: kFunctionCall) {
              Node @0 (tag: kReferenceCallBase) {
                Node @0 (tag: kReference) {
                  Node @0 (tag: kLocalRoot) {
                    Leaf @0 (#"super" @158-163: "super")
                  }
                  Node @1 (tag: kHierarchyExtension) {
                    Leaf @0 (#'.' @163-164: ".")
                    Node @1 (tag: kUnqualifiedId) {
                      Leaf @0 (#SymbolIdentifier @164-167: "new")
                    }
                  }
                }
                Node @1 (tag: kParenGroup) {
                  Leaf @0 (#'(' @167-168: "(")
                  Node @1 (tag: kArgumentList) {
                    Node @0 (tag: kExpression) {
                      Node @0 (tag: kFunctionCall) {
                        Node @0 (tag: kReference) {
                          Node @0 (tag: kLocalRoot) {
                            Node @0 (tag: kUnqualifiedId) {
                              Leaf @0 (#SymbolIdentifier @168-172: "name")
                            }
                          }
                        }
                      }
                    }
                    Leaf @1 (#',' @172-173: ",")
                    Node @2 (tag: kExpression) {
                      Node @0 (tag: kFunctionCall) {
                        Node @0 (tag: kReference) {
                          Node @0 (tag: kLocalRoot) {
                            Node @0 (tag: kUnqualifiedId) {
                              Leaf @0 (#SymbolIdentifier @174-180: "parent")
                            }
                          }
                        }
                      }
                    }
                  }
                  Leaf @2 (#')' @180-181: ")")
                }
              }
            }
            Leaf @1 (#';' @181-182: ";")
          }
        }
        Leaf @3 (#"endfunction" @185-196: "endfunction")
      }
      Node @2 (tag: kFunctionDeclaration) {
        Node @0 (tag: kFunctionHeader) {
          Leaf @1 (#"function" @199-207: "function")
          Node @3 (tag: kDataType) {
            Node @1 (tag: kDataTypePrimitive) {
              Leaf @0 (#"bit" @208-211: "bit")
            }
            Node @3 (tag: kPackedDimensions) {
            }
          }
          Node @4 (tag: kUnqualifiedId) {
            Leaf @0 (#SymbolIdentifier @212-224: "check_status")
          }
          Node @5 (tag: kParenGroup) {
            Leaf @0 (#'(' @224-225: "(")
            Node @1 (tag: kPortList) {
              Node @0 (tag: kPortItem) {
                Node @1 (tag: kDataTypeImplicitBasicIdDimensions) {
                  Node @0 (tag: kDataType) {
                    Node @1 (tag: kLocalRoot) {
                      Node @0 (tag: kUnqualifiedId) {
                        Leaf @0 (#SymbolIdentifier @225-245: "sc_uvc_sequence_item")
                      }
                    }
                    Node @3 (tag: kPackedDimensions) {
                    }
                  }
                  Node @1 (tag: kUnqualifiedId) {
                    Leaf @0 (#SymbolIdentifier @246-249: "req")
                  }
                  Node @2 (tag: kUnpackedDimensions) {
                  }
                }
              }
            }
            Leaf @2 (#')' @249-250: ")")
          }
          Leaf @6 (#';' @250-251: ";")
        }
        Node @2 (tag: kBlockItemStatementList) {
          Node @0 (tag: kDataDeclaration) {
            Node @1 (tag: kInstantiationBase) {
              Node @0 (tag: kInstantiationType) {
                Node @0 (tag: kDataType) {
                  Node @1 (tag: kDataTypePrimitive) {
                    Leaf @0 (#"bit" @256-259: "bit")
                  }
                  Node @3 (tag: kPackedDimensions) {
                  }
                }
              }
              Node @1 (tag: kGateInstanceRegisterVariableList) {
                Node @0 (tag: kRegisterVariable) {
                  Leaf @0 (#SymbolIdentifier @260-265: "error")
                  Node @1 (tag: kUnpackedDimensions) {
                  }
                  Node @2 (tag: kTrailingAssign) {
                    Leaf @0 (#'=' @266-267: "=")
                    Node @1 (tag: kExpression) {
                      Node @0 (tag: kNumber) {
                        Leaf @0 (#TK_DecNumber @268-269: "1")
                        Node @1 (tag: kBaseDigits) {
                          Leaf @0 (#TK_BinBase @269-271: "\'b")
                          Leaf @1 (#TK_BinDigits @271-272: "0")
                        }
                      }
                    }
                  }
                }
              }
            }
            Leaf @2 (#';' @272-273: ";")
          }
          Node @1 (tag: kAssignModifyStatement) {
            Node @0 (tag: kLPValue) {
              Node @0 (tag: kReference) {
                Node @0 (tag: kLocalRoot) {
                  Node @0 (tag: kUnqualifiedId) {
                    Leaf @0 (#SymbolIdentifier @278-283: "error")
                  }
                }
              }
            }
            Leaf @1 (#"|=" @284-286: "|=")
            Node @2 (tag: kExpression) {
              Node @0 (tag: kFunctionCall) {
                Node @0 (tag: kReferenceCallBase) {
                  Node @0 (tag: kReference) {
                    Node @0 (tag: kLocalRoot) {
                      Node @0 (tag: kUnqualifiedId) {
                        Leaf @0 (#SymbolIdentifier @287-296: "condition")
                      }
                    }
                  }
                  Node @1 (tag: kParenGroup) {
                    Leaf @0 (#'(' @296-297: "(")
                    Node @1 (tag: kArgumentList) {
                      Node @0 (tag: kExpression) {
                        Node @0 (tag: kUnaryPrefixExpression) {
                          Leaf @0 (#'!' @297-298: "!")
                          Node @1 (tag: kFunctionCall) {
                            Node @0 (tag: kReference) {
                              Node @0 (tag: kLocalRoot) {
                                Node @0 (tag: kUnqualifiedId) {
                                  Leaf @0 (#SymbolIdentifier @298-301: "req")
                                }
                              }
                              Node @1 (tag: kHierarchyExtension) {
                                Leaf @0 (#'.' @301-302: ".")
                                Node @1 (tag: kUnqualifiedId) {
                                  Leaf @0 (#SymbolIdentifier @302-310: "m_status")
                                }
                              }
                              Node @2 (tag: kDimensionScalar) {
                                Leaf @0 (#'[' @310-311: "[")
                                Node @1 (tag: kExpressionList) {
                                  Node @0 (tag: kExpression) {
                                    Node @0 (tag: kFunctionCall) {
                                      Node @0 (tag: kReference) {
                                        Node @0 (tag: kLocalRoot) {
                                          Node @0 (tag: kUnqualifiedId) {
                                            Leaf @0 (#SymbolIdentifier @311-332: "ERR_SINGLECHIP_BYPASS")
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                                Leaf @2 (#']' @332-333: "]")
                              }
                            }
                          }
                        }
                      }
                      Leaf @1 (#',' @333-334: ",")
                      Node @2 (tag: kExpression) {
                        Leaf @0 (#TK_StringLiteral @335-377: "\"SC_STS_NOTTODUT_NO_ERR_SINGLECHIP_BYPASS\"")
                      }
                      Leaf @3 (#',' @377-378: ",")
                      Node @4 (tag: kExpression) {
                        Node @0 (tag: kSystemTFCall) {
                          Leaf @0 (#SystemTFIdentifier @379-388: "$sformatf")
                          Node @1 (tag: kParenGroup) {
                            Leaf @0 (#'(' @388-389: "(")
                            Node @1 (tag: kArgumentList) {
                              Node @0 (tag: kExpression) {
                                Leaf @0 (#TK_StringLiteral @389-452: "\"Status bit is not set for transaction not directed to DUT\\n%s\"")
                              }
                              Leaf @1 (#',' @452-453: ",")
                              Node @2 (tag: kExpression) {
                                Node @0 (tag: kFunctionCall) {
                                  Node @0 (tag: kReferenceCallBase) {
                                    Node @0 (tag: kReference) {
                                      Node @0 (tag: kLocalRoot) {
                                        Node @0 (tag: kUnqualifiedId) {
                                          Leaf @0 (#SymbolIdentifier @454-457: "req")
                                        }
                                      }
                                      Node @1 (tag: kHierarchyExtension) {
                                        Leaf @0 (#'.' @457-458: ".")
                                        Node @1 (tag: kUnqualifiedId) {
                                          Leaf @0 (#SymbolIdentifier @458-464: "sprint")
                                        }
                                      }
                                    }
                                    Node @1 (tag: kParenGroup) {
                                      Leaf @0 (#'(' @464-465: "(")
                                      Leaf @2 (#')' @465-466: ")")
                                    }
                                  }
                                }
                              }
                            }
                            Leaf @2 (#')' @466-467: ")")
                          }
                        }
                      }
                      Leaf @5 (#',' @467-468: ",")
                      Node @6 (tag: kExpression) {
                        Node @0 (tag: kFunctionCall) {
                          Node @0 (tag: kReference) {
                            Node @0 (tag: kLocalRoot) {
                              Node @0 (tag: kUnqualifiedId) {
                                Leaf @0 (#MacroIdentifier @469-478: "`uvm_file")
                              }
                            }
                          }
                        }
                      }
                      Leaf @7 (#',' @478-479: ",")
                      Node @8 (tag: kExpression) {
                        Node @0 (tag: kFunctionCall) {
                          Node @0 (tag: kReference) {
                            Node @0 (tag: kLocalRoot) {
                              Node @0 (tag: kUnqualifiedId) {
                                Leaf @0 (#MacroIdentifier @480-489: "`uvm_line")
                              }
                            }
                          }
                        }
                      }
                    }
                    Leaf @2 (#')' @489-490: ")")
                  }
                }
              }
            }
            Leaf @3 (#';' @490-491: ";")
          }
          Node @2 (tag: kJumpStatement) {
            Leaf @0 (#"return" @496-502: "return")
            Node @1 (tag: kExpression) {
              Node @0 (tag: kFunctionCall) {
                Node @0 (tag: kReference) {
                  Node @0 (tag: kLocalRoot) {
                    Node @0 (tag: kUnqualifiedId) {
                      Leaf @0 (#SymbolIdentifier @503-508: "error")
                    }
                  }
                }
              }
            }
            Leaf @2 (#';' @508-509: ";")
          }
        }
        Leaf @3 (#"endfunction" @512-523: "endfunction")
      }
    }
    Leaf @2 (#"endclass" @524-532: "endclass")
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    formatterVerilog code formatter issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions