簡體   English   中英

TradingView 的 Pine Script v5 中不一致的過載行為

[英]Inconsistent overload behaviour in TradingView's Pine Script v5

我遇到了一個問題,我似乎在 Tradingview 的 pine 腳本 v5 中發現了一個關於重載功能的錯誤。
代碼示例:

//@version=5
indicator("Overload recognition from within custom functions not working consistently")

mult(array<float> x1, string x2) =>
    [x1, x2]

mult(array<string> x1, string x2) =>
    array.push(x1, x2)
    x1

mult(bool x1, string x2) =>
    [x1, x2]

myFn(y1) => // workaround: must define parameter type for the overload to work successfully
    mult(y1, "Overload NOT recognized (unless used previously or type is defined explicitly before function parameter")

var stringArray = array.new_string(0,na)
// mult(stringArray, "Overload working as expected")
// mult(true, "Overload working as expected")
myFn(stringArray)
plot(1, "Overload recognition from within custom functions not working consistently")

上面的代碼編譯會拋出錯誤:
 Add to Chart operation failed, reason: line 16: Cannot call 'mult' with argument 'x1'='y1'. An argument of 'string[]' type was used but a 'float[]' is expected
. 問題是,如果我使用對之前創建的字符串數組的y1引用並從myFn(y1)中調用mult(y1, "...") function ,編譯器將無法識別我的參數的引用類型並識別對應 function 過載,響應第一個匹配
似乎有一個參考錯誤,並且松樹腳本中有一個煩人的錯誤。

到目前為止可能的解決方法:
  1. 如果我向我的 function myFn(array<string> y1) =>提供類型定義,我實際上不想這樣做,則找到正確的重載
  2. 如果我取消注釋以下行: mult(stringArray, "Overload working as expected")在我的 function 調用之前,觸發一些與我相應的重載有關的重載的內部邏輯,在我的 fn 調用中也會發現重載 - 實際上甚至沒有一種解決方法......而只是一個事實
為什么封裝對我來說如此重要? 我在圖書館工作。
現在有人有更好的主意嗎?

截至今天( 2022-08-08 ),TradingView Pine團隊確認了該錯誤,並打開了一項任務來修復它。 希望我們能盡快得到電視更新來解決這個問題。
進一步研究:到目前為止,除了問題中建議的解決方法之外,沒有其他解決方法。 沒有數組操作有助於類型引用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM