繁体   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