为什么 X++ 编译会因为缺少所谓的可选参数而失败,具体取决于我最后保存的 class?

Why does X++ compilation fail because of missing allegedly optional argument depending which class I save last?

我有两个类:

[DataContractAttribute, SysOperationContractProcessingAttribute(classStr(CustBalanceUIBuilder)), SysOperationGroupAttribute('Date',"@ApplicationPlatform:SingleSpace", '1')]
public class CustBalanceDataContract implements SysOperationValidatable
{
    NoYesId     allowModifyDate;
    TransDate   transDate;
    str packedQuery;
 
    [DataMemberAttribute('DateTransactionDate'), SysOperationLabelAttribute(literalStr("@SYS11284")), SysOperationGroupMemberAttribute('Date'), SysOperationDisplayOrderAttribute('1')]
    public TransDate parmTransDate(TransDate _transDate = transDate)
    {
        transDate = _transDate;
        return transDate;
    }

    [DataMemberAttribute('DateControl'), SysOperationLabelAttribute("Enable date control"), SysOperationGroupMemberAttribute('Date'), SysOperationDisplayOrderAttribute('0')]
    public NoYesId parmAllowModifyDate(NoYesId _allowModifyDate = allowModifyDate)
    {
        allowModifyDate = _allowModifyDate;
        return allowModifyDate;
    }

    public boolean validate()
    {
        boolean ret = true;
        if(!transDate && allowModifyDate)
        {
            ret = checkFailed('Transaction date cannot be empty');
        }
        return ret;
    }

    [DataMemberAttribute, AifQueryTypeAttribute('_packedQuery',   querystr(CustTableSRS))]
    public str parmQuery(str _packedQuery = packedQuery)
    {
        packedQuery = _packedQuery;
        return packedQuery;
    }

    public Query getQuery()
    {
        return new Query(SysOperationHelper::base64Decode(packedQuery));
    }

    public void setQuery(Query _query)
    {
        packedQuery =SysOperationHelper::base64Encode(_query.pack());
    }

}

public class CustBalanceService
{
    public void processData(CustBalanceDataContract _custBalanceDataContract)
    {
        QueryRun queryRun = new queryRun(_custBalanceDataContract.getQuery());
        while(queryRun.next())
        {
            CustTable custTable = queryRun.get(tableNum(custTable));
 
            TransDate transDate = _custBalanceDataContract.parmTransDate();
            Amount balance = (transDate)
                ? custTable.balanceMST(dateNull(), transDate)
                : custTable.balanceMST();

            info(strFmt('%1 - %2', custTable.AccountNum, balance));
        }
    }
}

当它编译成功时,它的行为符合预期。

但是,如果我保存 CustBalanceDataContract,解决方案会重新编译,然后告诉我 CustBalanceService 中有一个错误,因为 _custBalanceDataContract.parmTransDate(); 缺少参数 1,您可以从签名 public TransDate parmTransDate(TransDate _transDate = transDate) 应该是可选参数。

但是如果我不做任何更改并再次保存 CustBalanceService,编译就会按预期进行。

这是编译器中的错误吗?这是一个已知问题吗?有解决办法吗? 代码是否真的有问题,即使在成功编译和执行后也可能导致失败?

我可以重现这个问题。

看来您有发现 . To answer your questions, yes, this could be an issue in the compiler. As I said in a comment on one of your other questions, 中的那些小特性的诀窍,因为它不属于 .NET 语言家族时有一些遗留包袱。总的来说,我认为在保存单个对象期间进行编译,甚至是整个 project/solution 的编译都比较好。根据我的经验,唯一可靠并产生有用结果的编译是完整 package/model 的编译(在 Visual Studio 中,它是由 Dynamics 365 > Build models... 菜单调用的) .

我认为您描述的问题不是已知问题。至少我不知道它,我不知道它的修复方法。不,我不认为代码有什么问题。如果它通过“Build models...”编译成功,就可以开始了。