gpt4 book ai didi

scala - 新的 dotty 运行时完全死在我身上

转载 作者:行者123 更新时间:2023-12-04 11:01:14 32 4
gpt4 key购买 nike

周六早上在这里。尝试学习新的 Scala 编译器 dotty。

安装在我的 Mac 上使用

brew install lampepfl/brew/dotty

安装成功。我有版本
dotr -version
Starting dotty REPL...
Dotty compiler version 0.20.0-RC1 -- Copyright 2002-2019, LAMP/EPFL

创建目录
mkdir dotty

Hello.scala 中编写了此代码
import Console._
@main def foo(s: String) : Unit =
println(s"Hello $s")

我能够编译它
dotc Hello.scala

收到一堆 .class.tasty文件

接下来我做了
dotr
:load Hello.scala

现在我得到了这个巨大的错误“爆炸”,dotr 运行时完全死亡并退出。

我做了什么导致这次爆炸?这不是一条友好的错误消息。
Exception in thread "main" scala.MatchError: PackageDef(Ident(<empty>),List(ValDef(rs$line$1,Ident(rs$line$1$),
Apply(Select(New(Ident(rs$line$1$)),<init>),List())), TypeDef(rs$line$1$,Template(DefDef(<init>,List(),List(List()),
TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Unit)],EmptyTree),List(Apply(Select(New(
TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class Object)]),<init>),List()), Select(Select(
Ident(_root_),scala),Serializable)),ValDef(_,SingletonTypeTree(Ident(rs$line$1)),EmptyTree),List(Import(Ident(Console),
List(ImportSelector(Ident(_),EmptyTree,EmptyTree))),DefDef(foo,List(),List(List(ValDef(s,Ident(String),EmptyTree))),
Ident(Unit),Apply(Ident(println),List(Apply(Select(Apply(Select(Select(Select(Ident(_root_),scala),StringContext),apply),
List(Typed(SeqLiteral(List(Literal(Constant(hello )), Literal(Constant())),TypeTree[TypeRef(TermRef(
ThisType(TypeRef(NoPrefix,module class scala)),module Predef),type String)]),
TypeTree[AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class <repeated>),
List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class scala)),module Predef),type String)))]))),s),
List(Typed(SeqLiteral(List(Ident(s)),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any)]),
TypeTree[AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class <repeated>),

List(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any)))]))))))))), TypeDef(foo,Template(DefDef(<init>,List(),List(List()),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Unit)],EmptyTree),List(Apply(Select(New(TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class Object)]),<init>),List())),ValDef(_,EmptyTree,EmptyTree),List(DefDef(main,List(),List(List(ValDef(args,TypeTree[AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Array),List(TypeRef(ThisType(TypeRef(NoPrefix,module class lang)),class String)))],EmptyTree))),TypeTree[TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Unit)],Try(Apply(Ident(foo),List(Apply(Apply(TypeApply(Ident(parseArgument),List(TypeTree[TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class scala)),module Predef),type String)])),List(Ident(args), Literal(Constant(0)))),List(Ident(given_FromString_String))))),List(CaseDef(Bind(error,Typed(Ident(_),TypeTree[TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class util)),module class CommandLineParser$)),class ParseError)])),EmptyTree,Apply(Ident(showError),List(Ident(error))))),EmptyTree))))))) (of class dotty.tools.dotc.ast.Trees$PackageDef)
at dotty.tools.repl.CollectTopLevelImports.topLevelImports$1(CollectTopLevelImports.scala:23)
at dotty.tools.repl.CollectTopLevelImports.run(CollectTopLevelImports.scala:28)
at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:315)
at scala.collection.immutable.List.map(List.scala:219)
at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:316)
at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:162)
at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
at dotty.tools.dotc.Run.runPhases$5(Run.scala:172)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:180)
at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:65)
at dotty.tools.dotc.Run.compileUnits(Run.scala:187)
at dotty.tools.dotc.Run.compileUnits(Run.scala:129)
at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:156)
at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:166)
at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:227)
at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:193)
at dotty.tools.repl.ReplDriver.run$$anonfun$1(ReplDriver.scala:136)
at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:148)
at dotty.tools.repl.ReplDriver.run(ReplDriver.scala:137)
at dotty.tools.repl.ReplDriver.interpretCommand(ReplDriver.scala:345)
at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:200)
at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:127)
at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:130)
at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:148)
at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:130)
at dotty.tools.repl.Main$.main(Main.scala:6)
at dotty.tools.repl.Main.main(Main.scala)

最佳答案

您没有指定程序参数

$ dotr foo
Illegal command line: more arguments expected

$ dotr foo World
Hello World

刚刚 dotr运行 REPL。在 REPL 中 :load <path>意思是“解释文件中的行”。怎么样 dotr应该得到程序参数?

关于scala - 新的 dotty 运行时完全死在我身上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58782434/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com