Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ final class taskSpec extends AsyncFreeSpec with Matchers {

val task1: Task[Int] = Task.now(1)

val ts = *[Task] /* .join */ apply Seq {
!Each(0 until 10) + !Shift(task1)
val ts = *[Task] {
Seq(
!Each(0 until 10) + !Shift(task1)
)
}

!Shift(ts) should be(1 until 11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,28 @@ class EachSpec extends AnyFreeSpec with Matchers {

"@reset parameter" in {
val seq = 1 to 10
def run(): Seq[Int] = reset(Seq {
val plus100 = reset(Seq {
!Each(seq) + 100
})
plus100.length should be(10)
!Each(plus100)
})

val result = run()
result.length should be(10)
result.last should be(110)
val plus100 = reify(
Seq { !Each(seq) + 100 }
)
"plus100.to[Seq[Int]]" shouldNot typeCheck
}

"reset block" in {
val seq = 1 to 10
def run(): Seq[Int] = reset(Seq {
val plus100 = reset {
def run() = reset({
val plus100: Seq[Int] = reset {
Seq(!Each(seq) + 100)
}
plus100.length should be(10)
!Each(plus100)
Seq(!Each(plus100))
})

val result = run()
result.length should be(10)
result.last should be(110)
}

"block without reset should behave the same as a block with a reset" in {
"block without reset should not behave the same as a block with a reset" in {
val seq = 1 to 10
def run(): Seq[Int] = reset {
val plus100 = {
Expand All @@ -64,14 +57,16 @@ class EachSpec extends AnyFreeSpec with Matchers {
"nested" - {

"each" - {
"explicit @reset" in {
"block" in {
val seq = 1 to 10

def run(): Seq[Int] = reset {
val plus100: Seq[Int] = Seq {
!Each(seq) + 100
val plus100: Seq[Int] = {
Seq(
!Each(seq) + 100
)
}
plus100.length should be(1)
plus100.length should be(10)
Seq(!Each(plus100))
}

Expand All @@ -84,9 +79,9 @@ class EachSpec extends AnyFreeSpec with Matchers {
val seq = 1 to 10

def run(): Seq[Int] = reset {
val plus100 = Seq {
val plus100 = Seq(
!Each(seq) + 100
}
)
plus100.length should be(1)
Seq(!Each(plus100))
}
Expand All @@ -100,9 +95,11 @@ class EachSpec extends AnyFreeSpec with Matchers {
val seq = 1 to 10

def run(): Seq[Int] = reset {
def plus100 = reset(Seq {
!Each(seq) + 100
})
def plus100 = reset(
Seq(
!Each(seq) + 100
)
)
plus100.length should be(10)
Seq(!Each(plus100))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class ForEachSpec extends AnyFreeSpec with Matchers {
val seq = 1 to 10

def run(): Unit = reset[Unit] {
val plus100 = Seq {
val plus100 = Seq(
!Each(seq) + 100
}
)
plus100.length should be(1)
!Each(plus100)
}
Expand Down
2 changes: 2 additions & 0 deletions macros-Reset/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ libraryDependencies += "junit" % "junit" % "4.13.2" % Test

libraryDependencies += "com.lihaoyi" %%% "utest" % "0.7.11" % Test

libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.11" % Test

testFrameworks += new TestFramework("utest.runner.Framework")
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ object Reset {
def reify[V](
body: quoted.Expr[_]
)(using valueType: quoted.Type[V]): quoted.Expr[_] = {
val bodyTerm = body.asTerm.underlyingArgument
val bodyTerm = body.asTerm/*.underlyingArgument*/
val reifiedTerm = if (dontSuspend) {
KeywordTree(bodyTerm).keywordTerm
} else {
Expand Down Expand Up @@ -164,7 +164,7 @@ object Reset {
valueType: quoted.Type[Value],
domainType: quoted.Type[Domain]
): quoted.Expr[Domain] = {
KeywordTree(body.asTerm.underlyingArgument) match {
KeywordTree(body.asTerm/*.underlyingArgument*/) match {
case Pure(pure, _)
if dontSuspend && TypeRepr.of[Value] <:< TypeRepr.of[Domain] =>
pure.asExprOf[Domain]
Expand Down Expand Up @@ -299,6 +299,10 @@ object Reset {
}
}
loop(elems, Queue.empty)
case namedArg@NamedArg(name, arg)=>
KeywordTree(arg).flatMap { pureArg =>
Pure(NamedArg.copy(namedArg)(name, pureArg), term.tpe)
}
case select @ Select(qualifier, name) =>
KeywordTree(qualifier).flatMap { pureQualifier =>
Pure(Select.copy(select)(pureQualifier, name), term.tpe)
Expand Down Expand Up @@ -398,6 +402,8 @@ object Reset {
Pure(Assign.copy(assign)(pureLhs, pureRhs), term.tpe)
}
}
case Inlined(_, Seq(), term) =>
KeywordTree(term)
case Inlined(_, bindings, term) =>
KeywordTree(qctx.reflect.Block(bindings, term))
case whileTerm @ qctx.reflect.While(cond, body) =>
Expand Down Expand Up @@ -1000,7 +1006,7 @@ object Reset {
Macros[qctx.type](
shouldResetNestedFunctions = translateNestedFunction,
dontSuspend = dontSuspend
).reify[V](body /*.underlyingArgument*/ )
).reify[V](body /*/*.underlyingArgument*/*/ )
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.thoughtworks.dsl.macros

import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
import com.thoughtworks.dsl.macros.Reset.Default.reset

class DottyIssue14510Spec extends AnyFreeSpec with Matchers {
"https://github.com/lampepfl/dotty/issues/14510" in {
def compareEnumValue() =
enum E:
case V
reset(E.V == E.V)
end compareEnumValue

compareEnumValue() should be(true)


}
}