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

meson format crashes in add_nl_after #13242

Closed
blue42u opened this issue May 22, 2024 · 1 comment · Fixed by #13244
Closed

meson format crashes in add_nl_after #13242

blue42u opened this issue May 22, 2024 · 1 comment · Fixed by #13244
Assignees

Comments

@blue42u
Copy link
Contributor

blue42u commented May 22, 2024

Describe the bug
meson format crashes when attempting to format one of our meson.build files.

To Reproduce

# Minimized meson.build
test(
  args: [
    shared_library(
      f'tstlib-@name@',
      build_by_default: false,
      override_options: opt,
    ),
  ],
)

test(
  should_fail: (
    settings.get('x', false) and not settings['y']
    and dep.version().version_compare('>=1.2.3')
  ),
)
$ meson format meson.build
Traceback (most recent call last):
  File ".../meson/mesonbuild/mesonmain.py", line 188, in run
    return options.run_func(options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../meson/mesonbuild/mformat.py", line 937, in run
    formatted = formatter.format(code, src_file)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../meson/mesonbuild/mformat.py", line 861, in format
    ast.accept(ArgumentFormatter(self.current_config))
  File ".../meson/mesonbuild/mparser.py", line 251, in accept
    func(self)
  File ".../meson/mesonbuild/ast/visitor.py", line 216, in visit_CodeBlockNode
    i.accept(self)
  File ".../meson/mesonbuild/mparser.py", line 251, in accept
    func(self)
  File ".../meson/mesonbuild/mformat.py", line 591, in visit_FunctionNode
    node.args.accept(self)
  File ".../meson/mesonbuild/mparser.py", line 251, in accept
    func(self)
  File ".../meson/mesonbuild/mformat.py", line 610, in visit_ArgumentNode
    super().visit_ArgumentNode(node)
  File ".../meson/mesonbuild/ast/visitor.py", line 317, in visit_ArgumentNode
    val.accept(self)
  File ".../meson/mesonbuild/mparser.py", line 251, in accept
    func(self)
  File ".../meson/mesonbuild/mformat.py", line 668, in visit_ParenthesizedNode
    node.inner.accept(self)
  File ".../meson/mesonbuild/mparser.py", line 251, in accept
    func(self)
  File ".../meson/mesonbuild/ast/visitor.py", line 200, in visit_AndNode
    self.visit_BinaryOperatorNode(node)
  File ".../meson/mesonbuild/ast/visitor.py", line 179, in visit_BinaryOperatorNode
    node.right.accept(self)
  File ".../meson/mesonbuild/mparser.py", line 251, in accept
    func(self)
  File ".../meson/mesonbuild/mformat.py", line 575, in visit_MethodNode
    node.source_object.accept(self)
  File ".../meson/mesonbuild/mparser.py", line 251, in accept
    func(self)
  File ".../meson/mesonbuild/mformat.py", line 580, in visit_MethodNode
    node.args.accept(self)
  File ".../meson/mesonbuild/mparser.py", line 251, in accept
    func(self)
  File ".../meson/mesonbuild/mformat.py", line 649, in visit_ArgumentNode
    self.add_nl_after(comma, self.level)
  File ".../meson/mesonbuild/mformat.py", line 545, in add_nl_after
    if not node.whitespaces.value or node.whitespaces.value == ' ':
           ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'value'

ERROR: Unhandled python exception

    This is a Meson bug and should be reported!

Expected behavior
meson format should format the code without raising an unhandled exception.

system parameters

  • Not a build
  • Ubuntu 24.04
  • Python 3.12.3
  • Meson 1.4.99 (aa9b7b9)
@eli-schwartz
Copy link
Member

/cc @bruchar1

@bruchar1 bruchar1 self-assigned this May 22, 2024
bruchar1 added a commit to bruchar1/meson that referenced this issue May 22, 2024
There was a case where a trailing comma was missing a whitespaces attribute

Fixes mesonbuild#13242
bruchar1 added a commit to bruchar1/meson that referenced this issue May 22, 2024
There was a case where a trailing comma was missing a whitespaces attribute

Fixes mesonbuild#13242
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants