[all-commits] [llvm/llvm-project] 819ff6: Improve dynamic AST matching diagnostics for conve...

Aaron Ballman via All-commits all-commits at lists.llvm.org
Wed Sep 23 09:14:07 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 819ff6b945816dce144c8be577a3c245f702b59c
      https://github.com/llvm/llvm-project/commit/819ff6b945816dce144c8be577a3c245f702b59c
  Author: Aaron Ballman <aaron at aaronballman.com>
  Date:   2020-09-23 (Wed, 23 Sep 2020)

  Changed paths:
    M clang/lib/ASTMatchers/Dynamic/Marshallers.h
    M clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

  Log Message:
  -----------
  Improve dynamic AST matching diagnostics for conversion errors

Currently, when marshaling a dynamic AST matchers, we check for the type
and value validity of matcher arguments at the same time for some matchers.
For instance, when marshaling hasAttr("foo"), the argument is first type
checked to ensure it's a string and then checked to see if that string can
locate an attribute with that name. Similar happens for other enumeration
conversions like cast kinds or unary operator kinds. If the type is
correct but the value cannot be looked up, we make a best-effort attempt
to find a nearby name that the user might have meant, but if one cannot
be found, we throw our hands up and claim the types don't match.

This has an unfortunate behavior that when the user enters something of
the correct type but a best guess cannot be located, you get confusing
error messages like:
Incorrect type for arg 1. (Expected = string) != (Actual = String).

This patch splits the argument check into two parts: if the types don't
match, give a type diagnostic. If the type matches but the value cannot
be converted, give a best guess diagnostic or a value could not be
located diagnostic. This addresses PR47057.




More information about the All-commits mailing list