Merge pull request #227 from max/redundant-expr-bug

Fix hash-consing of literals
This commit is contained in:
Sauyon Lee
2020-01-27 11:35:40 -08:00
committed by GitHub Enterprise
2 changed files with 13 additions and 5 deletions

View File

@@ -50,10 +50,16 @@ class HashableNode extends AstNode {
* Gets the value of this AST node, or the empty string if it does not have one.
*/
string getValue() {
literals(this, result, _)
or
not literals(this, _, _) and
result = ""
// for literals, get the exact value if available
if exists(this.(BasicLit).getExactValue())
then result = this.(BasicLit).getExactValue()
else
// for identifiers, get the name
if this instanceof Ident
then result = this.(Ident).getName()
else
// for everything else, give up
result = ""
}
/**

View File

@@ -24,5 +24,7 @@ func baz(b bool) int {
}
func main() {
foo(42)
if c == '\xA8' || c == '\xA9' {
foo(42)
}
}