From a3def146b85b1e2dc2721768f02222df5222428e Mon Sep 17 00:00:00 2001 From: beha Date: Sat, 23 Apr 2016 14:29:00 +0200 Subject: [PATCH 1/4] Added macro for passing all arguments of a method as implicit parameter --- README.md | 17 ++++++++++ .../main/scala/sourcecode/SourceContext.scala | 18 ++++++++++ .../src/test/scala/sourcecode/ArgsTests.scala | 34 +++++++++++++++++++ .../src/test/scala/sourcecode/Tests.scala | 1 + 4 files changed, 70 insertions(+) create mode 100644 sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala diff --git a/README.md b/README.md index 3628091..2bbe217 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ The kinds of compilation-time data that `sourcecode` provides are: you have multiple statements in a `{}` block, `sourcecode.Text` will only capture the source code for the last expression that gets returned. This implicit is slightly experimental; be sure to report any bugs you find! +- `sourcecode.Args`: the arguments that where provided to the nearest enclosing + method - `sourcecode.Name.Machine`, `sourcecode.FullName.Machine` and `sourcecode.Enclosing.Machine` which are similar to `sourcecode.Name`, `sourcecode.FullName` and `sourcecode.Enclosing` except they do not filter @@ -475,6 +477,21 @@ be printed. You can, or course, define your own `log` method in the same way, customizing it to print or not-print exactly what you want to see via the implicits that `sourcecode` provides! +`sourcecode.Args` can be used to access all parameters that where provided +to a method: + +```scala +def debug(implicit name: sourcecode.Name, args: sourcecode.Args): Unit = { + println(name.value + args.value.map(_.map(a => a.source + "=" + a.value).mkString("(", ", ", ")")).mkString("")) +} + +def foo(bar: String, baz: Int)(p: Boolean): Unit = { + debug +} + +foo("baz", 42)(true) // foo(bar=baz, baz=42)(p=true) +``` + Embedding Domain-Specific Languages ----------------------------------- diff --git a/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala b/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala index 27966e8..85cf601 100644 --- a/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala +++ b/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala @@ -111,6 +111,24 @@ object Text{ def apply[T](v: T): Text[T] = macro Impls.text[T] } + +case class Args(value: Seq[Seq[Text[_]]]) extends SourceValue[Seq[Seq[Text[_]]]] +object Args extends SourceCompanion[Seq[Seq[Text[_]]], Args](new Args(_)) { + implicit def generate: Args = macro impl + def impl(c: Compat.Context): c.Expr[Args] = { + import c.universe._ + + def enclosingMethod(owner: Symbol): MethodSymbol = + if (owner.isMethod) owner.asMethod else enclosingMethod(owner.owner) + + val method = enclosingMethod(Compat.enclosingOwner(c)) + val param = method.asMethod.paramLists + val texts = param.map(_.map(p => c.Expr[Text[_]](q"""sourcecode.Text($p, ${p.name.toString})"""))) + val textSeqs = texts.map(s => c.Expr(q"""Seq(..$s)""")) + c.Expr[Args](q"""Seq(..$textSeqs)""") + } +} + object Impls{ def text[T: c.WeakTypeTag](c: Compat.Context)(v: c.Expr[T]): c.Expr[sourcecode.Text[T]] = { import c.universe._ diff --git a/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala b/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala new file mode 100644 index 0000000..3a1e611 --- /dev/null +++ b/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala @@ -0,0 +1,34 @@ +package sourcecode + +object ArgsTests { + def apply() = { + def debug(implicit args: sourcecode.Args): Unit = { + assert(args.value.size == 2) + assert(args.value(0).size == 3) + assert(args.value(0)(0).source == "p1") + assert(args.value(0)(0).value == "text") + assert(args.value(0)(1).source == "p2") + assert(args.value(0)(1).value == 42) + assert(args.value(0)(2).source == "p3") + assert(args.value(0)(2).value == false) + assert(args.value(1)(0).source == "foo") + assert(args.value(1)(0).value == "foo") + assert(args.value(1)(1).source == "bar") + assert(args.value(1)(1).value == "bar") + } + + def foo(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String): Unit = { + debug + } + + def bar(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String): Unit = { + val bar = { + debug + "bar" + } + } + + foo("text", 42, false)("foo", "bar") + bar("text", 42, false)("foo", "bar") + } +} diff --git a/sourcecode/shared/src/test/scala/sourcecode/Tests.scala b/sourcecode/shared/src/test/scala/sourcecode/Tests.scala index 288a80b..546e576 100644 --- a/sourcecode/shared/src/test/scala/sourcecode/Tests.scala +++ b/sourcecode/shared/src/test/scala/sourcecode/Tests.scala @@ -20,6 +20,7 @@ object Tests{ Synthetic.run() ManualImplicit() TextTests() + ArgsTests() println("================LogExample================") logExample() From 695deca1ee2e901564bfc1aac46baa0c081ae774 Mon Sep 17 00:00:00 2001 From: beha Date: Sat, 23 Apr 2016 19:33:31 +0200 Subject: [PATCH 2/4] Fixed 2.10 compatibility --- sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala | 2 +- sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala b/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala index 85cf601..56f0efb 100644 --- a/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala +++ b/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala @@ -122,7 +122,7 @@ object Args extends SourceCompanion[Seq[Seq[Text[_]]], Args](new Args(_)) { if (owner.isMethod) owner.asMethod else enclosingMethod(owner.owner) val method = enclosingMethod(Compat.enclosingOwner(c)) - val param = method.asMethod.paramLists + val param = method.asMethod.paramss val texts = param.map(_.map(p => c.Expr[Text[_]](q"""sourcecode.Text($p, ${p.name.toString})"""))) val textSeqs = texts.map(s => c.Expr(q"""Seq(..$s)""")) c.Expr[Args](q"""Seq(..$textSeqs)""") diff --git a/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala b/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala index 3a1e611..bd4d0ed 100644 --- a/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala +++ b/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala @@ -2,6 +2,7 @@ package sourcecode object ArgsTests { def apply() = { + def debug(implicit args: sourcecode.Args): Unit = { assert(args.value.size == 2) assert(args.value(0).size == 3) @@ -11,6 +12,7 @@ object ArgsTests { assert(args.value(0)(1).value == 42) assert(args.value(0)(2).source == "p3") assert(args.value(0)(2).value == false) + assert(args.value(1).size == 2) assert(args.value(1)(0).source == "foo") assert(args.value(1)(0).value == "foo") assert(args.value(1)(1).source == "bar") From b36337aebab0f743da2c59bfbfe7b4c0cc614360 Mon Sep 17 00:00:00 2001 From: beha Date: Sun, 24 Apr 2016 14:31:22 +0200 Subject: [PATCH 3/4] - Fixed evaluation of arguments passed to the primary constructor with Scala 2.11 - Workaround for evaluation of arguments passed to the primary constructor with Scala 2.10 - Added test for implicit parameter lists - Added test for empty parameter lists --- README.md | 17 +++++++ build.sbt | 4 ++ .../main/scala-2.10/sourcecode/Compat.scala | 8 +++ .../main/scala-2.11/sourcecode/Compat.scala | 9 ++++ .../main/scala/sourcecode/SourceContext.scala | 7 +-- .../ArgsPrimaryConstructorTests.scala | 17 +++++++ .../ArgsPrimaryConstructorTests.scala | 17 +++++++ .../src/test/scala/sourcecode/ArgsTests.scala | 50 +++++++++++++------ .../src/test/scala/sourcecode/Tests.scala | 1 + 9 files changed, 109 insertions(+), 21 deletions(-) create mode 100644 sourcecode/shared/src/test/scala-2.10/sourcecode/ArgsPrimaryConstructorTests.scala create mode 100644 sourcecode/shared/src/test/scala-2.11/sourcecode/ArgsPrimaryConstructorTests.scala diff --git a/README.md b/README.md index 2bbe217..2ec23db 100644 --- a/README.md +++ b/README.md @@ -492,6 +492,23 @@ def foo(bar: String, baz: Int)(p: Boolean): Unit = { foo("baz", 42)(true) // foo(bar=baz, baz=42)(p=true) ``` +Please note, that it's currently not possible to access the arguments passed +to a constructor if you are using Scala 2.10, e.g. the following code will +work as expected with 2.11, but _not_ with 2.10: +```scala +def debug(implicit name: sourcecode.Name, args: sourcecode.Args): Unit = { + println(name.value + args.value.map(_.map(a => a.source + "=" + a.value).mkString("(", ", ", ")")).mkString("")) +} + +class Foo(arg1: String, arg2: Int) { + debug +} + +new Foo("bar", 42) +``` + +For 2.10 `sourcecode.Args.value will be an empty list.` + Embedding Domain-Specific Languages ----------------------------------- diff --git a/build.sbt b/build.sbt index ac3062b..c38d169 100644 --- a/build.sbt +++ b/build.sbt @@ -22,6 +22,10 @@ lazy val sourcecode = crossProject.settings( if (scalaVersion.value startsWith "2.10.") Seq(baseDirectory.value / ".."/"shared"/"src"/ "main" / "scala-2.10") else Seq(baseDirectory.value / ".."/"shared" / "src" / "main" / "scala-2.11") }, + unmanagedSourceDirectories in Test ++= { + if (scalaVersion.value startsWith "2.10.") Seq(baseDirectory.value / ".."/"shared"/"src"/ "test" / "scala-2.10") + else Seq(baseDirectory.value / ".."/"shared" / "src" / "test" / "scala-2.11") + }, publishTo := Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"), pomExtra := diff --git a/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala b/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala index 92fec60..af00445 100644 --- a/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala +++ b/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala @@ -9,4 +9,12 @@ object Compat{ .owner .asInstanceOf[c.Symbol] } + + def enclosingParamList(c: Context): List[List[c.Symbol]] = { + def nearestClassOrMethod(owner: c.Symbol): c.Symbol = + if (owner.isMethod || owner.isClass) owner else nearestClassOrMethod(owner.owner) + + val com = nearestClassOrMethod(enclosingOwner(c)) + if (com.isClass) List() else com.asMethod.paramss + } } \ No newline at end of file diff --git a/sourcecode/shared/src/main/scala-2.11/sourcecode/Compat.scala b/sourcecode/shared/src/main/scala-2.11/sourcecode/Compat.scala index 70ff8ac..b3c08e4 100644 --- a/sourcecode/shared/src/main/scala-2.11/sourcecode/Compat.scala +++ b/sourcecode/shared/src/main/scala-2.11/sourcecode/Compat.scala @@ -3,4 +3,13 @@ package sourcecode object Compat{ type Context = scala.reflect.macros.blackbox.Context def enclosingOwner(c: Context) = c.internal.enclosingOwner + + def enclosingParamList(c: Context): List[List[c.Symbol]] = { + def nearestEnclosingMethod(owner: c.Symbol): c.Symbol = + if (owner.isMethod) owner + else if (owner.isClass) owner.asClass.primaryConstructor + else nearestEnclosingMethod(owner.owner) + + nearestEnclosingMethod(enclosingOwner(c)).asMethod.paramLists + } } \ No newline at end of file diff --git a/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala b/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala index 56f0efb..6ba86c5 100644 --- a/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala +++ b/sourcecode/shared/src/main/scala/sourcecode/SourceContext.scala @@ -117,12 +117,7 @@ object Args extends SourceCompanion[Seq[Seq[Text[_]]], Args](new Args(_)) { implicit def generate: Args = macro impl def impl(c: Compat.Context): c.Expr[Args] = { import c.universe._ - - def enclosingMethod(owner: Symbol): MethodSymbol = - if (owner.isMethod) owner.asMethod else enclosingMethod(owner.owner) - - val method = enclosingMethod(Compat.enclosingOwner(c)) - val param = method.asMethod.paramss + val param = Compat.enclosingParamList(c) val texts = param.map(_.map(p => c.Expr[Text[_]](q"""sourcecode.Text($p, ${p.name.toString})"""))) val textSeqs = texts.map(s => c.Expr(q"""Seq(..$s)""")) c.Expr[Args](q"""Seq(..$textSeqs)""") diff --git a/sourcecode/shared/src/test/scala-2.10/sourcecode/ArgsPrimaryConstructorTests.scala b/sourcecode/shared/src/test/scala-2.10/sourcecode/ArgsPrimaryConstructorTests.scala new file mode 100644 index 0000000..3204e8c --- /dev/null +++ b/sourcecode/shared/src/test/scala-2.10/sourcecode/ArgsPrimaryConstructorTests.scala @@ -0,0 +1,17 @@ +package sourcecode + +object ArgsPrimaryConstructorTests { + def apply() = { + + var args: Seq[Seq[(String, Any)]] = Seq() + + def debug(implicit arguments: sourcecode.Args): Unit = args = arguments.value.map(_.map(t => t.source -> t.value)) + + class Foo(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String) { + debug + } + + new Foo("text", 42, false)("foo", "bar") + assert(args == Seq()) + } +} diff --git a/sourcecode/shared/src/test/scala-2.11/sourcecode/ArgsPrimaryConstructorTests.scala b/sourcecode/shared/src/test/scala-2.11/sourcecode/ArgsPrimaryConstructorTests.scala new file mode 100644 index 0000000..1c053b9 --- /dev/null +++ b/sourcecode/shared/src/test/scala-2.11/sourcecode/ArgsPrimaryConstructorTests.scala @@ -0,0 +1,17 @@ +package sourcecode + +object ArgsPrimaryConstructorTests { + def apply() = { + + var args: Seq[Seq[(String, Any)]] = Seq() + + def debug(implicit arguments: sourcecode.Args): Unit = args = arguments.value.map(_.map(t => t.source -> t.value)) + + class Foo(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String) { + debug + } + + new Foo("text", 42, false)("foo", "bar") + assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar"))) + } +} diff --git a/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala b/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala index bd4d0ed..a737625 100644 --- a/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala +++ b/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala @@ -3,21 +3,9 @@ package sourcecode object ArgsTests { def apply() = { - def debug(implicit args: sourcecode.Args): Unit = { - assert(args.value.size == 2) - assert(args.value(0).size == 3) - assert(args.value(0)(0).source == "p1") - assert(args.value(0)(0).value == "text") - assert(args.value(0)(1).source == "p2") - assert(args.value(0)(1).value == 42) - assert(args.value(0)(2).source == "p3") - assert(args.value(0)(2).value == false) - assert(args.value(1).size == 2) - assert(args.value(1)(0).source == "foo") - assert(args.value(1)(0).value == "foo") - assert(args.value(1)(1).source == "bar") - assert(args.value(1)(1).value == "bar") - } + var args: Seq[Seq[(String, Any)]] = Seq() + + def debug(implicit arguments: sourcecode.Args): Unit = args = arguments.value.map(_.map(t => t.source -> t.value)) def foo(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String): Unit = { debug @@ -30,7 +18,39 @@ object ArgsTests { } } + def baz: Unit = { + debug + } + + def withImplicit(p1: String, p2: Long, p3: Boolean)(implicit foo: String): Unit = { + debug + } + + class Foo(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String) { + + def this(p1: String, p2: Long) = { + this(p1, p2, false)("foo", "bar") + debug + } + } + + new Foo("text", 42) + assert(args == Seq(Seq("p1" -> "text", "p2" -> 42))) + foo("text", 42, false)("foo", "bar") + assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar"))) + bar("text", 42, false)("foo", "bar") + assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar"))) + + baz + assert(args == Seq()) + + withImplicit("text", 42, false)("foo") + assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo"))) + + implicit val implicitFoo = "bar" + withImplicit("text", 42, false) + assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "bar"))) } } diff --git a/sourcecode/shared/src/test/scala/sourcecode/Tests.scala b/sourcecode/shared/src/test/scala/sourcecode/Tests.scala index 546e576..22e4b30 100644 --- a/sourcecode/shared/src/test/scala/sourcecode/Tests.scala +++ b/sourcecode/shared/src/test/scala/sourcecode/Tests.scala @@ -21,6 +21,7 @@ object Tests{ ManualImplicit() TextTests() ArgsTests() + ArgsPrimaryConstructorTests() println("================LogExample================") logExample() From ebc1b114b8d2680f4a5eea4e62d652c4b7f0f80e Mon Sep 17 00:00:00 2001 From: Benjamin Hagemeister Date: Mon, 25 Apr 2016 12:35:05 +0200 Subject: [PATCH 4/4] Fixed evaluation of constructor parameter with Scala 2.10 --- README.md | 17 ----------------- build.sbt | 4 ---- .../src/main/scala-2.10/sourcecode/Compat.scala | 7 ++++++- .../ArgsPrimaryConstructorTests.scala | 17 ----------------- .../ArgsPrimaryConstructorTests.scala | 17 ----------------- .../src/test/scala/sourcecode/ArgsTests.scala | 4 ++++ .../src/test/scala/sourcecode/Tests.scala | 1 - 7 files changed, 10 insertions(+), 57 deletions(-) delete mode 100644 sourcecode/shared/src/test/scala-2.10/sourcecode/ArgsPrimaryConstructorTests.scala delete mode 100644 sourcecode/shared/src/test/scala-2.11/sourcecode/ArgsPrimaryConstructorTests.scala diff --git a/README.md b/README.md index 2ec23db..2bbe217 100644 --- a/README.md +++ b/README.md @@ -492,23 +492,6 @@ def foo(bar: String, baz: Int)(p: Boolean): Unit = { foo("baz", 42)(true) // foo(bar=baz, baz=42)(p=true) ``` -Please note, that it's currently not possible to access the arguments passed -to a constructor if you are using Scala 2.10, e.g. the following code will -work as expected with 2.11, but _not_ with 2.10: -```scala -def debug(implicit name: sourcecode.Name, args: sourcecode.Args): Unit = { - println(name.value + args.value.map(_.map(a => a.source + "=" + a.value).mkString("(", ", ", ")")).mkString("")) -} - -class Foo(arg1: String, arg2: Int) { - debug -} - -new Foo("bar", 42) -``` - -For 2.10 `sourcecode.Args.value will be an empty list.` - Embedding Domain-Specific Languages ----------------------------------- diff --git a/build.sbt b/build.sbt index c38d169..ac3062b 100644 --- a/build.sbt +++ b/build.sbt @@ -22,10 +22,6 @@ lazy val sourcecode = crossProject.settings( if (scalaVersion.value startsWith "2.10.") Seq(baseDirectory.value / ".."/"shared"/"src"/ "main" / "scala-2.10") else Seq(baseDirectory.value / ".."/"shared" / "src" / "main" / "scala-2.11") }, - unmanagedSourceDirectories in Test ++= { - if (scalaVersion.value startsWith "2.10.") Seq(baseDirectory.value / ".."/"shared"/"src"/ "test" / "scala-2.10") - else Seq(baseDirectory.value / ".."/"shared" / "src" / "test" / "scala-2.11") - }, publishTo := Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"), pomExtra := diff --git a/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala b/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala index af00445..31ba2e0 100644 --- a/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala +++ b/sourcecode/shared/src/main/scala-2.10/sourcecode/Compat.scala @@ -15,6 +15,11 @@ object Compat{ if (owner.isMethod || owner.isClass) owner else nearestClassOrMethod(owner.owner) val com = nearestClassOrMethod(enclosingOwner(c)) - if (com.isClass) List() else com.asMethod.paramss + if (com.isClass) { + val pc = com.typeSignature.members.filter(m => m.isMethod && m.asMethod.isPrimaryConstructor) + pc.head.asMethod.paramss + } else { + com.asMethod.paramss + } } } \ No newline at end of file diff --git a/sourcecode/shared/src/test/scala-2.10/sourcecode/ArgsPrimaryConstructorTests.scala b/sourcecode/shared/src/test/scala-2.10/sourcecode/ArgsPrimaryConstructorTests.scala deleted file mode 100644 index 3204e8c..0000000 --- a/sourcecode/shared/src/test/scala-2.10/sourcecode/ArgsPrimaryConstructorTests.scala +++ /dev/null @@ -1,17 +0,0 @@ -package sourcecode - -object ArgsPrimaryConstructorTests { - def apply() = { - - var args: Seq[Seq[(String, Any)]] = Seq() - - def debug(implicit arguments: sourcecode.Args): Unit = args = arguments.value.map(_.map(t => t.source -> t.value)) - - class Foo(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String) { - debug - } - - new Foo("text", 42, false)("foo", "bar") - assert(args == Seq()) - } -} diff --git a/sourcecode/shared/src/test/scala-2.11/sourcecode/ArgsPrimaryConstructorTests.scala b/sourcecode/shared/src/test/scala-2.11/sourcecode/ArgsPrimaryConstructorTests.scala deleted file mode 100644 index 1c053b9..0000000 --- a/sourcecode/shared/src/test/scala-2.11/sourcecode/ArgsPrimaryConstructorTests.scala +++ /dev/null @@ -1,17 +0,0 @@ -package sourcecode - -object ArgsPrimaryConstructorTests { - def apply() = { - - var args: Seq[Seq[(String, Any)]] = Seq() - - def debug(implicit arguments: sourcecode.Args): Unit = args = arguments.value.map(_.map(t => t.source -> t.value)) - - class Foo(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String) { - debug - } - - new Foo("text", 42, false)("foo", "bar") - assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar"))) - } -} diff --git a/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala b/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala index a737625..31a28a3 100644 --- a/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala +++ b/sourcecode/shared/src/test/scala/sourcecode/ArgsTests.scala @@ -27,6 +27,7 @@ object ArgsTests { } class Foo(p1: String, p2: Long, p3: Boolean)(foo: String, bar: String) { + debug def this(p1: String, p2: Long) = { this(p1, p2, false)("foo", "bar") @@ -34,6 +35,9 @@ object ArgsTests { } } + new Foo("text", 42, false)("foo", "bar") + assert(args == Seq(Seq("p1" -> "text", "p2" -> 42, "p3" -> false), Seq("foo" -> "foo", "bar" -> "bar"))) + new Foo("text", 42) assert(args == Seq(Seq("p1" -> "text", "p2" -> 42))) diff --git a/sourcecode/shared/src/test/scala/sourcecode/Tests.scala b/sourcecode/shared/src/test/scala/sourcecode/Tests.scala index 22e4b30..546e576 100644 --- a/sourcecode/shared/src/test/scala/sourcecode/Tests.scala +++ b/sourcecode/shared/src/test/scala/sourcecode/Tests.scala @@ -21,7 +21,6 @@ object Tests{ ManualImplicit() TextTests() ArgsTests() - ArgsPrimaryConstructorTests() println("================LogExample================") logExample()