-
Notifications
You must be signed in to change notification settings - Fork 4
Finding implicit this. #54
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import structs/[ArrayList, HashMap, MultiMap] | ||
| import ../frontend/BuildParams | ||
| import Node, Type, TypeDecl, FunctionDecl, FunctionCall, Visitor, VariableAccess, PropertyDecl, ClassDecl, CoverDecl | ||
| import tinker/[Trail, Resolver, Response, Errors] | ||
|
|
||
|
|
@@ -155,9 +156,16 @@ Addon: class extends Node { | |
| } | ||
|
|
||
| if (call suggest(fDecl, res, trail)) { | ||
| if (fDecl hasThis() && !call getExpr()) { | ||
| // add `this` if needed. | ||
| call setExpr(VariableAccess new("this", call token)) | ||
| if (!call getExpr()) { | ||
| if (fDecl hasThis()) { | ||
| // add `this` if needed. | ||
| call setExpr(VariableAccess new("this", call token)) | ||
| } | ||
| // Not yet tested | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just have to assume that it does not give false detection until someone uses addons while not using implicit this. |
||
| if (res params explicitThis) { | ||
| name := fDecl hasThis() ? "this" : "This" | ||
| call token printMessage("Implicit " + name + " detected for call to " + fDecl name + "!") | ||
| } | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1253,6 +1253,29 @@ TypeDecl: abstract class extends Declaration { | |
| varAcc := VariableAccess new("this", access token) | ||
| varAcc reverseExpr = access | ||
| access expr = varAcc | ||
| if (res params explicitThis) { | ||
| mustBeExplicit := true | ||
|
|
||
| // Generic variables do not require explicit this | ||
| if (vDecl getType()) { | ||
| if (vDecl getType() toString() == "Class") { | ||
| mustBeExplicit = false | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filter out variables like |
||
| } | ||
| } | ||
|
|
||
| // Access to a variable from within its own declaration does not have to be explicit | ||
| depth := trail getSize() - 1 | ||
| while (depth >= 0) { | ||
| if (trail get(depth) == vDecl) { | ||
| mustBeExplicit = false | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filter out access from inside the variable's own declaration since most of them are generated getters and setters. |
||
| } | ||
| depth -= 1 | ||
| } | ||
|
|
||
| if (mustBeExplicit) { | ||
| access token printMessage("Implicit this detected for variable access of " + vDecl name + "!") | ||
| } | ||
| } | ||
| } | ||
| return 0 | ||
| } | ||
|
|
@@ -1360,8 +1383,14 @@ TypeDecl: abstract class extends Declaration { | |
| if (fDecl) { | ||
| if (call debugCondition()) " \\o/ Found fDecl for %s, it's %s" format(call name, fDecl toString()) println() | ||
| if (call suggest(fDecl, res, trail)) { | ||
| if (fDecl hasThis() && !call getExpr()) { | ||
| call setExpr(VariableAccess new("this", call token)) | ||
| if (!call getExpr()) { | ||
| if (fDecl hasThis()) { | ||
| call setExpr(VariableAccess new("this", call token)) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding the |
||
| } | ||
| if (res params explicitThis && fDecl name != "init" && fDecl name != ClassDecl DEFAULTS_FUNC_NAME) { | ||
| name := fDecl hasThis() ? "this" : "This" | ||
| call token printMessage("Implicit " + name + " detected for call to " + fDecl name + "!") | ||
| } | ||
| } | ||
| return 0 | ||
| } | ||
|
|
@@ -1391,6 +1420,9 @@ TypeDecl: abstract class extends Declaration { | |
| // if the variable is static, use class scope not instance | ||
| name := vDecl isStatic() ? "This" : "this" | ||
| call setExpr(VariableAccess new(name, call token)) | ||
| if (res params explicitThis) { | ||
| call token printMessage("Implicit " + name + " detected for call to " + vDecl name + "!") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that this is function calls by pointer from the table since variables are used for access. |
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write
--explicitThisto turn on the warnings.