Skip to content

Three valid scripts that translate but do not build: single-line bodies and na() of a string array #281

Closed

Description

@letiep97

Summary

Each script below runs on TradingView. pineforge-codegen 1.9.0 either rejects it in the front end or emits C++ that clang cannot compile. Writing the function body on indented lines, using string(na) and initialising the array in the constructor builds and runs.

Case 1 is next to #230, which 1.9.0 fixes: the := form now builds, but a parameter read after the first comma is still unknown.

Versions

pineforge-codegen 1.9.0, pineforge-engine v1.9.0 (ec44968), Apple clang, macOS arm64. The errors come from the front end and from type checks on the generated C++, so they should not depend on the platform.

All three share this head and tail:

//@version=6
strategy('repro')
type Box
    array<string> items
// case body here
if bar_index == 5
    strategy.entry('L', strategy.long)

1. A parameter read after the first comma of a single-line body

var b = Box.new(array.new<string>())
add(Box x, string s) => array.push(x.items, s), x.items.size()
add(b, 'a')

<input>:6:49: Unknown variable 'x' — not a PineForge builtin or a declared variable.

add(Box x, string s) => x.items.push(s), 1 (the parameter only before the first comma) builds.

2. A string ternary with na as a single-line body returns double

var b = Box.new(array.new<string>())
take(Box x) => x.items.size() > 2 ? x.items.shift() : na
b.items.push('a')
take(b)

error: no viable conversion from returned value of type 'std::string' to function return type 'double'

The function's type seems to come from the na branch. string(na) in that branch builds.

3. na() of an array<string> field

var b = Box.new()
if na(b.items)
    b.items := array.new<string>()

error: no matching function for call to 'is_na' — the candidates in pineforge/na.hpp take double, an integral type or the UDT, none takes std::vector<std::string>.

Expected

All three build and run as on TradingView: the single-line body sees its parameters in every comma-separated statement, the function in case 2 returns string, and na() accepts any array reference.

Workaround

Write the body on indented lines, give the na branch its type (string(na)), and create the array in the constructor instead of testing it with na(). Each case was checked against a control that differs in that one place and builds.

cc @luisleo526

Activity

  1. luisleo526 commented on Nov 1, 2026

    @luisleo526
    Contributor

    Thank you for the detailed report, and sorry for the slow reply here.

    All three cases now translate, build and run on current main (codegen c1cc532b with engine 009cb95c), and so do your workaround forms; we ran your three scripts as written. Cases 1 and 2 were fixed by #290. The fixes will ship in the next release; we will name the release version in this issue when they ship.

  2. luisleo526 commented on Nov 3, 2026

    @luisleo526
    Contributor

    As promised above, the release version: the fixes (cases 1 and 2 by #290, all three cases translating, building and running on main) ship in PineForge Codegen 1.10.0, the next release (planned for tonight, Taipei time). Closing as fixed; please reopen if any of the three scripts still fails after upgrading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions