Summary
The validator flags .new() calls and field access on user-defined types (UDTs) as Undefined namespace or variable, even though type X declarations and X.new(...) are valid Pine v6 (and have been supported since v5.7).
Closely related to #10 (enums) — both UDTs and enums declared via type/enum aren't tracked by accurateValidator.
Environment
- Extension:
jpantsjoha.pinescript-v6-extension v0.4.4
- VS Code: any recent
- OS: platform-independent
Minimal repro
//@version=6
indicator("UDT repro", overlay=true)
type Foo
float a
float b
newFoo() =>
Foo.new(na, na)
var Foo state = newFoo()
plot(close)
Expected
No diagnostics. The script compiles and runs correctly in the TradingView Pine Editor.
Actual
Red squiggle on Foo.new(na, na):
Undefined namespace or variable 'Foo'
Same error appears on any later Foo.field or Foo.new(...) reference.
Root cause
In accurateValidator.ts, checkUndefinedNamespaces treats every X.Y pattern as namespace access and checks only three sources:
if (!this.knownNamespaces.has(namespace) &&
!this.declaredVariables.has(namespace) &&
!this.isBuiltInVariable(namespace)) {
this.addError(... `Undefined namespace or variable '${namespace}'`);
}
There's no tracking of type X declarations, so UDT names never enter any registry the check consults.
Suggested minimal fix
- Add a
declaredTypes: Set<string> field to AccurateValidator.
- Clear it at the top of
validate(), alongside declaredVariables.clear().
- In the existing first-pass loop, also call
collectDeclaredTypes(line) which matches /^\s*(?:export\s+)?type\s+([A-Za-z_]\w*)\s*$/ and adds the captured name to declaredTypes.
- Extend the check above with
!this.declaredTypes.has(namespace).
This suppresses the false positive without trying to validate UDT field access (which would be a larger change requiring multi-line block parsing and a field registry).
I've been running a local patch along these lines against v0.4.4 — it cleanly removes the false positives without re-introducing other ones (verified with NoSuchThing.foo() counter-tests that still correctly flag).
If you'd like a PR with the minimal fix + a test fixture, happy to send one.
Why this matters
UDTs are the idiomatic way to bundle related state in modern v6 indicators and strategies. Right now the extension produces persistent red diagnostics on any non-trivial v6 codebase using type.
Summary
The validator flags
.new()calls and field access on user-defined types (UDTs) asUndefined namespace or variable, even thoughtype Xdeclarations andX.new(...)are valid Pine v6 (and have been supported since v5.7).Closely related to #10 (enums) — both UDTs and enums declared via
type/enumaren't tracked byaccurateValidator.Environment
jpantsjoha.pinescript-v6-extensionv0.4.4Minimal repro
Expected
No diagnostics. The script compiles and runs correctly in the TradingView Pine Editor.
Actual
Red squiggle on
Foo.new(na, na):Same error appears on any later
Foo.fieldorFoo.new(...)reference.Root cause
In accurateValidator.ts,
checkUndefinedNamespacestreats everyX.Ypattern as namespace access and checks only three sources:There's no tracking of
type Xdeclarations, so UDT names never enter any registry the check consults.Suggested minimal fix
declaredTypes: Set<string>field toAccurateValidator.validate(), alongsidedeclaredVariables.clear().collectDeclaredTypes(line)which matches/^\s*(?:export\s+)?type\s+([A-Za-z_]\w*)\s*$/and adds the captured name todeclaredTypes.!this.declaredTypes.has(namespace).This suppresses the false positive without trying to validate UDT field access (which would be a larger change requiring multi-line block parsing and a field registry).
I've been running a local patch along these lines against v0.4.4 — it cleanly removes the false positives without re-introducing other ones (verified with
NoSuchThing.foo()counter-tests that still correctly flag).If you'd like a PR with the minimal fix + a test fixture, happy to send one.
Why this matters
UDTs are the idiomatic way to bundle related state in modern v6 indicators and strategies. Right now the extension produces persistent red diagnostics on any non-trivial v6 codebase using
type.