fix(resolution): gate the Lua/Luau annotation pattern against method-call self-match (#1124) (#1131)
Lua method-call syntax (lg:Log()) is byte-identical to the Luau type-annotation shape (lg: Logger), and the receiver-type scan starts on the call's own line — so any PascalCase method call self-matched as "type = Log" before the scan reached the real declaration, silently dropping the calls edge whenever two or more classes shared a method name. The annotation pattern now rejects a capture followed by any of Lua's three call forms; its leading [\w.] lookahead alternative prevents backtracking from shrinking the capture to dodge the gate. Gated rather than dropped: the pattern is the only type source for Luau typed params and annotated locals whose initializer isn't T.new(). Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
cf86fe8198
commit
e53968cae8
@@ -1148,7 +1148,17 @@ function localReceiverTypePatterns(language: Language, r: string): RegExp[] {
|
||||
return [
|
||||
new RegExp(`\\b${r}\\b\\s*=\\s*([A-Z][\\w]*)\\.new\\b`), // local lg = Logger.new()
|
||||
new RegExp(`\\b${r}\\b\\s*=\\s*([A-Z][\\w]*)\\s*\\(`), // local lg = Logger(...) (callable table)
|
||||
new RegExp(`\\b${r}\\b\\s*:\\s*([A-Z][\\w.]*)`), // Luau: local lg: Logger / typed param
|
||||
// Luau annotation (`local lg: Logger`) / typed param — but Lua's
|
||||
// method-call syntax is the IDENTICAL `receiver:Name` shape, and the
|
||||
// backward scan starts on the call's own line, so without a gate any
|
||||
// PascalCase method call (`lg:Log()`, the Roblox convention)
|
||||
// self-matches as "type = Log" before the scan reaches the real
|
||||
// declaration (#1124). The lookahead rejects a capture followed by
|
||||
// any of Lua's three call forms — `(args)`, `"s"`/`'s'`/`[[s]]`,
|
||||
// `{t}` — and its leading `[\w.]` alternative stops backtracking from
|
||||
// shrinking the capture to dodge the gate (`lg:Log()` would otherwise
|
||||
// still match, as `Lo`).
|
||||
new RegExp(`\\b${r}\\b\\s*:\\s*([A-Z][\\w.]*)(?![\\w.]|\\s*[({"'\\[])`), // local lg: Logger / typed param
|
||||
];
|
||||
case 'r':
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user