- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 Scala 3 的编译器称为库,它在编译后为每个源提供 CompilationUnit
。这有 tpdTree
,听上去应该包含类型信息。
我正在尝试遍历树以获得任何类型符号:
atPhase(Phases.typerPhase.next) {
// traverse unit.tpdTree...
}
树上行走的样子:
class ValExtractor(tpes: Set[String]) extends tpd.TreeTraverser:
def isAcceptableType(tpe: Types.Type)(using ctx: Context): Boolean =
tpe.baseClasses.exists { sym =>
tpes.contains(sym.fullName.toString)
}
override def traverse(tree: tpd.Tree)(using ctx: Context): Unit =
tree match
case tpd.ValDef(name, tpt, _) if isAcceptableType(tpt.tpe) =>
println("do something")
case t: tpd.Template => this((), t.body)
case t: tpd.PackageDef => this((), t.stats)
case t: tpd.TypeDef => this((), t.rhs)
case _ => ()
end ValExtractor
我明白了
[info] assertion failed: denotation class Int invalid in run 1. ValidFor: Period(1..55, run = 2)
[info] scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
[info] dotty.tools.dotc.core.Denotations$SingleDenotation.updateValidity(Denotations.scala:719)
[info] dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:744)
[info] dotty.tools.dotc.core.Denotations$SingleDenotation.toNewRun$1(Denotations.scala:803)
[info] dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:877)
[info] dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:122)
[info] dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:116)
[info] dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:109)
[info] dotty.tools.dotc.core.Symbols$.toDenot(Symbols.scala:502)
[info] dotty.tools.dotc.core.Denotations$SingleDenotation.updateValidity(Denotations.scala:718)
[info] dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:744)
[info] dotty.tools.dotc.core.Denotations$SingleDenotation.toNewRun$1(Denotations.scala:803)
[info] dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:877)
[info] dotty.tools.dotc.core.Types$NamedType.computeDenot(Types.scala:2253)
[info] dotty.tools.dotc.core.Types$NamedType.denot(Types.scala:2213)
[info] dotty.tools.dotc.core.Types$NamedType.info(Types.scala:2201)
[info] dotty.tools.dotc.core.Types$TypeRef.underlying(Types.scala:2693)
[info] dotty.tools.dotc.core.Types$Type.baseClasses(Types.scala:600)
我做错了什么?
在我的例子中,我的方法中有 (using ctx: Context)
,但显然它与运行上下文不匹配。如下所示显式传递它修复了它:
atPhase(Phases.typerPhase.next) {
(new ValExtractor(valTypes.toSet)).getVals(unit.tpdTree)
}(using run.runContext)
最佳答案
您需要在 run
值与创建定义时相同的上下文中运行查询(或者是稍后运行,但较早运行无效)。
您看到的错误消息是您在运行 1 时询问符号的表示,这在概念上是在运行 2 时创建之前。
参见 https://www.youtube.com/watch?v=WxyyJyB_Ssc用于解释运行/阶段概念的视频。
关于斯卡拉 3 : "assertion failed: denotation class Int invalid in run 1.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71559189/
我看到了构造 THE x. A在 Isabelle/HOL 标准库的源代码中。这个构造表示什么?好像和SOME x. A差不多. 最佳答案 THE是一个描述运算符,如 SOME ,但具有较弱的公理化。
我使用 matplot 库在 python 中绘制绘图。我必须生成的数字非常大,所以轴上的刻度也是很大的数字并且占用大量空间。我试图将它们呈现为幂(例如,我想要 10^8 而不是勾选 10000000
我使用 matplot 库在 python 中绘制绘图。我必须生成的数字非常大,所以轴上的刻度也是很大的数字并且占用大量空间。我试图将它们呈现为幂(例如,我想要 10^8 而不是勾选 10000000
对于那些知道的人来说,这可能是一个愚蠢的问题,但这里是。 尝试在查询中使用占位符。我发现以下工作: SELECT day, @dy:=CAST( CASE day
我有一个需要分解的 xml。但我收到此错误 XQuery [nodes()]: The name "s"does not denote a namespace. 我有以下格式的 xml
实现 Spring Integration 的 Spring boot 应用程序正在尝试为其入站 channel 适配器访问 UNC 路径。 问题是我收到以下异常: 13:29:52.925 [ta
在 Delphi/Free Pascal 中: ^ 是一个运算符还是仅仅表示一个指针类型? 示例代码 program Project1; {$APPTYPE CONSOLE} var P: ^
在 Azure 应用程序配置中,我将我的设置命名为:“Section1__SubSection1__MySetting”。当尝试将配置绑定(bind)到 .NET 6 应用程序中相应的 Options
我作为初学者正在学习 c#,并制作了一个程序,该程序为用户提供从骰子中随机数直到得到 6 的随机数。这是我的完整代码: using System; class HelloWorld { stati
我将 Scala 3 的编译器称为库,它在编译后为每个源提供 CompilationUnit。这有 tpdTree,听上去应该包含类型信息。 我正在尝试遍历树以获得任何类型符号: atPhase(P
我将 Scala 3 的编译器称为库,它在编译后为每个源提供 CompilationUnit。这有 tpdTree,听上去应该包含类型信息。 我正在尝试遍历树以获得任何类型符号: atPhase(P
https://jsfiddle.net/boriskay/thsmdqrt/ 这是一个简单的文本字段测验。我需要的是在每个文本字段后的右侧直接显示复选标记或 X(错误)图标。 文本字段有一个 CSS
在 Node 异步方法中,我们将任务定义为“一个”或“两个”,如下例所示。有没有办法使该文本动态化? var async = require("async"); async.paral
在 JSF 和 Facelets 标签中,这些前缀到底是什么? h: c: 女: 界面: 例如:h:head c:catch f:event ui:decorate 等 最佳答案 前缀用于将标记限定为
我有以下代码在我的 C# 泛型函数中产生编译问题: static void solve () { int[] vals = RA(); } 和我的 RA 函数: static T[] RA (
我是一名优秀的程序员,十分优秀!