UserNobody14 / tree-sitter-dart

Attempt to make a tree-sitter grammar for dart
MIT License
56 stars 33 forks source link

"Get and Set Identifiers" test? #30

Closed VanessaHenderson closed 2 years ago

VanessaHenderson commented 2 years ago

Hi there! I'm looking at seeing if we can leverage this project to add Dart as a supported language in Semgrep. I noticed that in the declarations.txt file in the test folder, there is a test for Get and Set Identifiers. It is trying to set _count and _root on an instantiated Set object, but since these variables don't exist in the Dart Set Object, this isn't a valid method unless you were trying to test an error?

The testcase currently doesn't have the expected below it like the others, in its current state it'd be as follows. The ERROR is where its trying to set _count and _root

(program
        (class_definition (identifier)
            (class_body
              (method_signature (function_signature 
                (type_identifier)  
                (identifier) 
                (formal_parameter_list)))
              (function_body
                (block (ERROR (function_signature (type_identifier) (identifier) 
                   (ERROR (identifier)) (formal_parameter_list)) 
                   (identifier) (identifier) (identifier) (identifier))
                   (return_statement (identifier))
                  )))))

I guess what I'm trying to understand is, is this what you were expecting to test with this testcase?

UserNobody14 commented 2 years ago

That test is based on files we found while scanning through various dart codebases, mostly flutter, wherein we found issues with variables and identifiers that were named "get" or "set". I've just recently redone these scans and didn't run across any of those issues, so it's possible it was just a bug in the core dart compiler that allowed those variables to be named that. At any rate, the test was left in just in case anyone found a way to fix it. The _count and _root variables don't matter and shouldn't affect the outcome in any way. The item causing the error here is the name of the variable "set", which is also a keyword, but is (annoyingly) also allowed as a variable name based on our previous scans of the flutter codebase.

Let me know if you fix it, or if you need any more help integrating our codebase into semgrep! Hope we can help!

VanessaHenderson commented 2 years ago

Ahhh, okay that makes a lot of sense! From what I can tell, Dart still allows variable names as "set" and it'll still compile (I created a dummy class but named the variable set), but yes the Parser does still show the error. In the spec set and get aren't reserved words, I wonder if that'll change in the future.

Interesting issue for sure!