wix-incubator / accord

Accord: A sane validation library for Scala
http://wix.github.io/accord/
Other
530 stars 55 forks source link

Error:(8, 30) exception during macro expansion: java.lang.ClassCastException: scala.reflect.internal.Trees$Block cannot be cast to scala.reflect.api.Trees$CaseDefApi #146

Open SavtechSolutions opened 5 years ago

SavtechSolutions commented 5 years ago

Error:(8, 30) exception during macro expansion: java.lang.ClassCastException: scala.reflect.internal.Trees$Block cannot be cast to scala.reflect.api.Trees$CaseDefApi at scala.reflect.api.Trees$Transformer$$anonfun$transformCaseDefs$1.apply(Trees.scala:2581) at scala.reflect.api.Trees$Transformer$$anonfun$transformCaseDefs$1.apply(Trees.scala:2581) at scala.collection.immutable.List.loop$1(List.scala:176) at scala.collection.immutable.List.mapConserve(List.scala:200) at scala.reflect.api.Trees$Transformer.transformCaseDefs(Trees.scala:2581) at scala.reflect.internal.Trees$class.itransform(Trees.scala:1382) at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16) at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16) at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2555) at com.wix.accord.transform.PatternHelper$$anon$3.transform(PatternHelper.scala:107) at com.wix.accord.transform.PatternHelper$class.transformByPattern(PatternHelper.scala:108) at com.wix.accord.transform.ValidationTransform.transformByPattern(ValidationTransform.scala:24) at com.wix.accord.transform.ValidationTransform$$anonfun$processBooleanExpressions$1.applyOrElse(ValidationTransform.scala:208) at com.wix.accord.transform.ValidationTransform$$anonfun$processBooleanExpressions$1.applyOrElse(ValidationTransform.scala:206) at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36) at com.wix.accord.transform.ValidationTransform$$anonfun$rewriteValidationRules$1.applyOrElse(ValidationTransform.scala:200) at com.wix.accord.transform.ValidationTransform$$anonfun$rewriteValidationRules$1.applyOrElse(ValidationTransform.scala:200) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167) at com.wix.accord.transform.ValidationTransform$$anonfun$3$$anonfun$5.apply(ValidationTransform.scala:177) at com.wix.accord.transform.ValidationTransform$$anonfun$3$$anonfun$5.apply(ValidationTransform.scala:170) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) at scala.collection.immutable.List.foreach(List.scala:392) at scala.collection.TraversableLike$class.map(TraversableLike.scala:234) at scala.collection.immutable.List.map(List.scala:296) at com.wix.accord.transform.ValidationTransform$$anonfun$3.applyOrElse(ValidationTransform.scala:170) at com.wix.accord.transform.ValidationTransform$$anonfun$3.applyOrElse(ValidationTransform.scala:161) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167) at com.wix.accord.transform.PatternHelper$$anon$2.traverse(PatternHelper.scala:85) at scala.reflect.api.Trees$Traverser.traverseTrees(Trees.scala:2484) at scala.reflect.internal.Trees$class.traverseComponents$1(Trees.scala:1234) at scala.reflect.internal.Trees$class.itraverse(Trees.scala:1330) at scala.reflect.internal.SymbolTable.itraverse(SymbolTable.scala:16) at scala.reflect.internal.SymbolTable.itraverse(SymbolTable.scala:16) at scala.reflect.api.Trees$Traverser.traverse(Trees.scala:2475) at com.wix.accord.transform.PatternHelper$$anon$2.traverse(PatternHelper.scala:87) at com.wix.accord.transform.PatternHelper$class.collectFromPattern(PatternHelper.scala:89) at com.wix.accord.transform.ValidationTransform.collectFromPattern(ValidationTransform.scala:24) at com.wix.accord.transform.ValidationTransform.transformed(ValidationTransform.scala:220) at com.wix.accord.transform.ValidationTransform$.apply(ValidationTransform.scala:240) validator[CtptyLoanColl] { arg =>

The exception is for the following validator:

`import com.wix.accord.dsl._ import com.wix.accord.transform.ValidationTransform.TransformedValidator

object IHSValidator { implicit val ctptyLoanCollValidator: TransformedValidator[CtptyLoanColl] = validator[CtptyLoanColl] { arg => if (arg.LN_TypeOfSft == "SLEB") arg.LN_BaseProd match { case "AGRI" => arg.LN_SubProd is in("GROS", "SOFT", "POTA", "OOLI", "DIRY", "FRST", "SEAF", "LSTK", "GRIN", "OTHR") case "NRGY" => arg.LN_SubProd is in("GROS", "SOFT", "POTA", "OOLI", "DIRY", "FRST", "SEAF", "LSTK", "GRIN", "OTHR") case "ENVR" => arg.LN_SubProd is in("GROS", "SOFT", "POTA", "OOLI", "DIRY", "FRST", "SEAF", "LSTK", "GRIN", "OTHR") case "FRGT" => arg.LN_SubProd is in("GROS", "SOFT", "POTA", "OOLI", "DIRY", "FRST", "SEAF", "LSTK", "GRIN", "OTHR") case "FRTL" => arg.LN_SubProd is in("GROS", "SOFT", "POTA", "OOLI", "DIRY", "FRST", "SEAF", "LSTK", "GRIN", "OTHR") case "INDP" => arg.LN_SubProd is in("GROS", "SOFT", "POTA", "OOLI", "DIRY", "FRST", "SEAF", "LSTK", "GRIN", "OTHR") case "METL" => arg.LN_SubProd is in("GROS", "SOFT", "POTA", "OOLI", "DIRY", "FRST", "SEAF", "LSTK", "GRIN", "OTHR") case "PAPR" => arg.LN_SubProd is in("GROS", "SOFT", "POTA", "OOLI", "DIRY", "FRST", "SEAF", "LSTK", "GRIN", "OTHR") case "POLY" => arg.LN_SubProd is in("GROS", "SOFT", "POTA", "OOLI", "DIRY", "FRST", "SEAF", "LSTK", "GRIN", "OTHR") } } } `

Only works when I comment all cases but one. As soon as I add another one, the compilation fails.

Relevant case class:

`import java.io.PrintWriter import java.lang.{Boolean => JBoolean} import java.sql.{Date, Timestamp} import java.time.format.DateTimeFormatter

import scala.reflect.runtime.universe._

case class CtptyLoanColl(IM_SubmitterID: String = null, IM_ParticipantID: String = null, IM_RepCpCodeType: String = null, CP_RepCp: String = null, CP_NatureOfRepCp: String = null, IM_NatureOfOtherCp: String = null, CP_SecOfRepCp: String = null, CP_AdditionalSecClass: String = null, IM_BranchOfRepCpType: String = null, CP_BranchOfRepCp: String = null, IM_BranchOfOtherCpType: String = null, CP_BranchOfOtherCp: String = null, CP_CpSide: String = null, CP_EntResponsibleForRep: String = null, IM_OtherCpType: String = null, CP_OtherCp: String = null, CP_CountryOfOtherCp: String = null, IM_CountryOfRpCp: String = null, IM_SecOfOthrCp: String = null, IM_BeneficiaryType: String = null, CP_Beneficiary: String = null, IM_TriPartyAgentType: String = null, CP_TriPartyAgent: String = null, IM_BrokerCodeType: String = null, CP_Broker: String = null, IM_ClearingMemberCodeType: String = null, CP_ClearingMember: String = null, IM_CsdParticipantCodeType: String = null, CP_CsdParticipant: String = null, IM_CsdIndirectParticipantCodeType: String = null, CP_CsdIndirectParticipant: String = null, IM_AgentLenderCodeType: String = null, CP_AgentLender: String = null, IM_TradeRef: String = null, LN_Uti: String = null, LN_RepTrackingNo: String = null, LN_EventDate: Date = null, IM_AsOfDateTime: Timestamp = null, LN_TypeOfSft: String = null, LN_Cleared: JBoolean = null, LN_ClearingTime: Timestamp = null, LN_Ccp: String = null, LN_TradingVenue: String = null, LN_MasterAgreementType: String = null, LN_OtherMasterAgreementType: String = null, LN_MasterAgreementVer: String = null, IM_MasterAgreementID: String = null, LN_ExecutionTime: Timestamp = null, LN_ValueDateStartDate: Date = null, LN_MaturityDateEndDate: Date = null, LN_TerminationDate: Date = null, LN_MinimumNoticePer: String = null, LN_EarliestCallBackDate: Date = null, LN_GeneralCollIndicator: String = null, LN_DbvIndicator: JBoolean = null, LN_MethodUsedToProvideColl: String = null, LN_OpenTerm: JBoolean = null, LN_TerminationOptionality: String = null, LN_FixedRate: String = null, LN_DayCountConvention: String = null, LN_FlotRate: String = null, LN_FlotRateRefPerTimePer: String = null, LN_FlotRateRefPerMultiplier: String = null, LN_FlotRatePaymentFreqTimePer: String = null, LN_FlotRatePaymentFreqMultiplier: String = null, LN_FlotRateResetFreqTimePer: String = null, LN_FlotRateResetFreqMultiplier: String = null, LN_Spread: String = null, LN_AdjustedRate: String = null, LN_RateDate: Date = null, LN_PrinAmtOnValueDate: String = null, LN_PrinAmtOnMaturityDate: String = null, LN_PrinAmtCcy: String = null, IM_MarketIdentifierTypes: String = null, IM_MarketIdentifierCodes: String = null, LN_TypeOfAsset: String = null, LN_SecId: String = null, IM_SecurityDescr: String = null, LN_ClassOfASec: String = null, LN_BaseProd: String = null, LN_SubProd: String = null, LN_FurtherSubProd: String = null, LN_QuantityOrNominalAmt: String = null, LN_UnitOfMeasure: String = null, LN_CcyOfNominalAmt: String = null, LN_SecOrCommodityPrice: String = null, LN_SecOrCommodityPriceBasis: String = null, LN_SecOrCommodityPricePct: String = null, LN_SecOrCommodityPriceYield: String = null, LN_PriceCcy: String = null, LN_SecQuality: String = null, LN_MaturityOfSec: Date = null, LN_JurisdictionOfIssuer: String = null, LN_LeiOfIssuer: String = null, LN_SecType: String = null, LN_LoanValue: String = null, LN_MarketValue: String = null, LN_FixedRebRate: String = null, LN_FlotRebRate: String = null, LN_FlotRebRateRefPerTimePer: String = null, LN_FlotRebRateRefPerMultiplier: String = null, LN_FlotRebRatePaymentFreqTimePer: String = null, LN_FlotRebRatePaymentFreqMultiplier: String = null, LN_FlotRebRateResetFreqTimePer: String = null, LN_FlotRebRateResetFreqMultiplier: String = null, LN_SpreadOfRebRate: String = null, LN_LenFee: String = null, LN_ExclusiveArrangements: JBoolean = null, CO_UncollateralisedSlFlag: JBoolean = null, CO_CollisationOfNetExposure: JBoolean = null, CO_ValueDateOfColl: Date = null, CO_TypeOfCollComponent: String = null, IM_CollAssetIdentifierTypes: String = null, IM_CollAssetIdentifierCodes: String = null, IM_CollSecDescr: String = null, CO_CashCollAmt: String = null, CO_CashCollCcy: String = null, CO_IdOfASecUsedAsColl: String = null, CO_ClassOfASecUsedAsColl: String = null, CO_BaseProd: String = null, CO_SubProd: String = null, CO_FurtherSubProd: String = null, CO_CollQuantityOrNominalAmt: String = null, CO_CollUnitOfMeasure: String = null, CO_CcyOfCollNominalAmt: String = null, CO_PriceCcy: String = null, CO_PricePerUnit: String = null, CO_PricePerUnitBasis: String = null, CO_PricePerUnitPct: String = null, CO_PricePerUnitYield: String = null, CO_CollMarketValue: String = null, CO_HaircutOrMargin: String = null, CO_CollQuality: String = null, CO_MaturityOfSec: Date = null, CO_JurisdictionOfIssuer: String = null, CO_LeiOfIssuer: String = null, CO_CollType: String = null, CO_AvailabilityForCollReuse: JBoolean = null, CO_CollBasketId: String = null, CO_PortfolioCode: String = null, CO_ActionType: String = null, CO_Level: String = null, IM_DelegatedReporting: String = null, IM_OthrCptyAdditionalSecClass: String = null, IM_ShellTradeRef: String = null, IM_ShellTradeQttyNom: String = null, IM_CCPCodeType: String = null, IM_EEARptCpty: JBoolean = null, IM_MemberOfESCB: JBoolean = null, IM_UserDefined1: String = null, IM_UserDefined2: String = null, IM_UserDefined3: String = null, IM_UserDefined4: String = null, IM_UserDefined5: String = null, IM_UserDefined6: String = null, IM_UserDefined7: String = null, IM_UserDefined8: String = null, IM_UserDefined9: String = null, IM_UserDefined10: String = null) { def toCSV: String = this.productIterator.map { case null => "" case timestamp: Timestamp => DateTimeFormatter.ISO_INSTANT.format(timestamp.toInstant) case value => value.toString.replace("\"", "\\"") }.mkString(",") }

object CtptyLoanColl { val header: String = typeOf[CtptyLoanColl].members.collect { case m: MethodSymbol if m.isCaseAccessor => m }.map(_.name.toString).toList.reverse.mkString(",")

def print(writer: PrintWriter, records: Seq[String], submitterID: String, feedType: String = "Trade", version: String = "3.00", sequence: Int, timestamp: String): Unit = { writer.println(s"DataSupplier,$submitterID,FeedType,$feedType,SchemaVersion,$version,SeqNo,$sequence,DateProduced,$timestamp,RecordCount,${records.size}") writer.println(CtptyLoanColl.header) records.foreach(writer.println) } } `

SavtechSolutions commented 5 years ago

Scala 2.11.12, Accord 0.7.3, JDK 8