在IntelliJ中编译Scala时断言失败

时间:2017-03-03 23:22:13

标签: scala intellij-idea

我在编译期间遇到此错误。我不知道这个具体的断言是什么意思。我试图创建一个基类,然后是两个扩展它的类。这两个类基本上是一种以更简单的方式使用基类的方法。我不清楚为什么扩展会导致这个编译问题。

Error:scalac: Error: assertion failed: {
  <artifact> val x$7: com.acme.ruleengine.expressions.utility.LastExpression[Double] @scala.reflect.internal.annotations.uncheckedBounds = com.acme.ruleengine.expressions.data.TimeSeriesExpression.apply[Double](metricName).last;
  <artifact> val x$8: com.acme.ruleengine.Context = context;
  <artifact> val x$9: String = ruleName;
  <artifact> val x$10: String = ruleFriendlyName;
  <artifact> val x$11: String = ruleDescription;
  <artifact> val x$12: com.acme.server.sensor.models.managementprocess.alerts.dto.AlertSeverity = severity;
  <artifact> val x$13: String = metricName;
  <artifact> val x$14: Any = threshold;
  <artifact> val x$15: com.acme.data.conditions.TagsStoreCondition = metaCondition;
  <artifact> val x$16: String = applicableMetricTag;
  <artifact> val x$17: String = alertItemDescriptionFormat;
  <artifact> val x$18: String = alertDescription;
  <artifact> val x$19: String = baseRemediationText;
  <artifact> val x$20: com.acme.server.rules.library.ThresholdDirection.ThresholdDirection = thresholdDirection;
  <artifact> val x$21: String = alertItemsHeader;
  <artifact> val x$22: Seq[(scala.util.matching.Regex, String)] @scala.reflect.internal.annotations.uncheckedBounds = itemSpecificDescription;
  NumericThresholdOnDoubleMetricWithItemsTemplateRule.super.<init>(x$8, x$9, x$10, x$11, x$12, x$7, x$13, x$14, x$15, x$16, x$17, x$18, x$19, x$20, x$21, x$22)
}(<vendorToRemediationText: error>)
java.lang.AssertionError: assertion failed: {
  <artifact> val x$7: com.acme.ruleengine.expressions.utility.LastExpression[Double] @scala.reflect.internal.annotations.uncheckedBounds = com.acme.ruleengine.expressions.data.TimeSeriesExpression.apply[Double](metricName).last;
  <artifact> val x$8: com.acme.ruleengine.Context = context;
  <artifact> val x$9: String = ruleName;
  <artifact> val x$10: String = ruleFriendlyName;
  <artifact> val x$11: String = ruleDescription;
  <artifact> val x$12: com.acme.server.sensor.models.managementprocess.alerts.dto.AlertSeverity = severity;
  <artifact> val x$13: String = metricName;
  <artifact> val x$14: Any = threshold;
  <artifact> val x$15: com.acme.data.conditions.TagsStoreCondition = metaCondition;
  <artifact> val x$16: String = applicableMetricTag;
  <artifact> val x$17: String = alertItemDescriptionFormat;
  <artifact> val x$18: String = alertDescription;
  <artifact> val x$19: String = baseRemediationText;
  <artifact> val x$20: com.acme.server.rules.library.ThresholdDirection.ThresholdDirection = thresholdDirection;
  <artifact> val x$21: String = alertItemsHeader;
  <artifact> val x$22: Seq[(scala.util.matching.Regex, String)] @scala.reflect.internal.annotations.uncheckedBounds = itemSpecificDescription;
  NumericThresholdOnDoubleMetricWithItemsTemplateRule.super.<init>(x$8, x$9, x$10, x$11, x$12, x$7, x$13, x$14, x$15, x$16, x$17, x$18, x$19, x$20, x$21, x$22)
}(<vendorToRemediationText: error>)
    at scala.tools.nsc.typechecker.Typers$Typer.computeParamAliases(Typers.scala:2037)
    at scala.tools.nsc.typechecker.Typers$Typer.typedDefDef(Typers.scala:2215)
    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5308)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5359)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423)
    ...
    at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:101)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:47)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:41)
    at org.jetbrains.jps.incremental.scala.local.IdeaIncrementalCompiler.compile(IdeaIncrementalCompiler.scala:29)
    at org.jetbrains.jps.incremental.scala.local.LocalServer.compile(LocalServer.scala:26)
    at org.jetbrains.jps.incremental.scala.remote.Main$.make(Main.scala:67)
    at org.jetbrains.jps.incremental.scala.remote.Main$.nailMain(Main.scala:24)
    at org.jetbrains.jps.incremental.scala.remote.Main.nailMain(Main.scala)
    at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.martiansoftware.nailgun.NGSession.run(NGSession.java:319)

代码是:

package com.acme.server.rules.library

case class NumericThresholdWithItemsTemplateRule(context: Context, ruleName: String, ruleFriendlyName: String, ruleDescription: String,
                                                               severity: AlertSeverity = AlertSeverity.ERROR,
                                                               value: Expression[Option[Double]],
                                                               metricName: String, threshold: Any, metaCondition: TagsStoreCondition = True,
                                                               applicableMetricTag: String, alertItemDescriptionFormat: String, alertDescription: String, baseRemediationText: String, thresholdDirection: ThresholdDirection = ThresholdDirection.ABOVE,
                                                               alertItemsHeader: String, itemSpecificDescription: Seq[(Regex, String)] = Seq(".*".r -> ""))
                                                              (vendorToRemediationText: (String, String)*) extends PerDeviceRule with RuleHelper {

  ...
}

case class NumericThresholdOnDoubleMetricWithItemsTemplateRule(override val context: Context, override val ruleName: String, override val ruleFriendlyName: String, override val ruleDescription: String,
                                                               override val severity: AlertSeverity = AlertSeverity.ERROR,
                                                               override val metricName: String, override val threshold: Any, override val metaCondition: TagsStoreCondition = True,
                                                               override val applicableMetricTag: String, override val alertItemDescriptionFormat: String, override val alertDescription: String, override val baseRemediationText: String, override val thresholdDirection: ThresholdDirection = ThresholdDirection.ABOVE,
                                                               override val alertItemsHeader: String, override val itemSpecificDescription: Seq[(Regex, String)] = Seq(".*".r -> ""))
                                                              (vendorToRemediationText: (String, String)*) extends NumericThresholdWithItemsTemplateRule(
                                                                value = TimeSeriesExpression[Double](metricName).last,
                                                                context = context, ruleName = ruleName, ruleFriendlyName = ruleFriendlyName, ruleDescription = ruleDescription, severity = severity, metricName = metricName, threshold = threshold, metaCondition = metaCondition, applicableMetricTag = applicableMetricTag, alertItemDescriptionFormat = alertItemDescriptionFormat, alertDescription = alertDescription, baseRemediationText = baseRemediationText, thresholdDirection = thresholdDirection, alertItemsHeader = alertItemsHeader, itemSpecificDescription = itemSpecificDescription)(vendorToRemediationText) {

}

case class NumericThresholdOnComplexMetricWithItemsTemplateRule(override val context: Context, override val ruleName: String, override val ruleFriendlyName: String, override val ruleDescription: String,
                                                               override val severity: AlertSeverity = AlertSeverity.ERROR,
                                                               override val metricName: String, override val threshold: Any, override val metaCondition: TagsStoreCondition = True,
                                                               override val applicableMetricTag: String, override val alertItemDescriptionFormat: String, override val alertDescription: String, override val baseRemediationText: String, override val thresholdDirection: ThresholdDirection = ThresholdDirection.ABOVE,
                                                               override val alertItemsHeader: String, override val itemSpecificDescription: Seq[(Regex, String)] = Seq(".*".r -> ""))
                                                              (vendorToRemediationText: (String, String)*) extends NumericThresholdWithItemsTemplateRule(
  value = ToDoubleExpression(SingleSnapshotExtractExpression(SnapshotExpression(metricName).asSingle().mostRecent(), "value")),
  context = context, ruleName = ruleName, ruleFriendlyName = ruleFriendlyName, ruleDescription = ruleDescription, severity = severity, metricName = metricName, threshold = threshold, metaCondition = metaCondition, applicableMetricTag = applicableMetricTag, alertItemDescriptionFormat = alertItemDescriptionFormat, alertDescription = alertDescription, baseRemediationText = baseRemediationText, thresholdDirection = thresholdDirection, alertItemsHeader = alertItemsHeader, itemSpecificDescription = itemSpecificDescription)(vendorToRemediationText) {

}

1 个答案:

答案 0 :(得分:1)

禁止使用case-to-case继承。我想,这可能是你的主要问题,尽量避免它。

看看这个:

scala> case class A(b: String)
defined class A

scala> case class B(b: String) extends A(b)
<console>:13: error: case class B has case ancestor A, but case-to-case inheritance is prohibited. To overcome this limitation, use extractors to pattern match on non-leaf nodes.
       case class B(b: String) extends A(b)

有关案例类继承的有用链接: Scala case class inheritance What is *so* wrong with case class inheritance?