How to deprecate a parameter with default value in Scala?












5















In the metrics-scala library we have the following method:



def timer(name: String, scope: String = null): Timer


I want to deprecate the scope parameter and remove it from the next major version.



I tried this:



def timer(name: String): Timer
@deprecated(...)
def timer(name: String, scope: String): Timer


But that causes binary backward compatibility problems (see below *) already within the current major version.



I also tried this:



def timer(name: String, @deprecated(...) scope: String = null): Timer


But that gives warnings inside timer, and not for the caller of timer.



Did I miss something or is it really not possible to deprecate a parameter with default values?



(*) Mima report for option 1:



sbt:metrics4-scala-root> mimaReportBinaryIssues
[error] * synthetic method timer$default$2()java.lang.String in class nl.grons.metrics4.scala.MetricBuilder does not have a correspondent in current version
[error] filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("nl.grons.metrics4.scala.MetricBuilder.timer$default$2")









share|improve this question

























  • the first option should work. why are you saying it causes backwards compatibility=

    – pedrorijo91
    Nov 25 '18 at 9:57











  • Because Mima says so. I updated the question.

    – Erik van Oosten
    Nov 25 '18 at 18:47













  • A brute-force way would be to add a deprecated method def timer$default$2(): String = null. Though Oleg's answer is better, I think.

    – Alexey Romanov
    Nov 26 '18 at 10:37
















5















In the metrics-scala library we have the following method:



def timer(name: String, scope: String = null): Timer


I want to deprecate the scope parameter and remove it from the next major version.



I tried this:



def timer(name: String): Timer
@deprecated(...)
def timer(name: String, scope: String): Timer


But that causes binary backward compatibility problems (see below *) already within the current major version.



I also tried this:



def timer(name: String, @deprecated(...) scope: String = null): Timer


But that gives warnings inside timer, and not for the caller of timer.



Did I miss something or is it really not possible to deprecate a parameter with default values?



(*) Mima report for option 1:



sbt:metrics4-scala-root> mimaReportBinaryIssues
[error] * synthetic method timer$default$2()java.lang.String in class nl.grons.metrics4.scala.MetricBuilder does not have a correspondent in current version
[error] filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("nl.grons.metrics4.scala.MetricBuilder.timer$default$2")









share|improve this question

























  • the first option should work. why are you saying it causes backwards compatibility=

    – pedrorijo91
    Nov 25 '18 at 9:57











  • Because Mima says so. I updated the question.

    – Erik van Oosten
    Nov 25 '18 at 18:47













  • A brute-force way would be to add a deprecated method def timer$default$2(): String = null. Though Oleg's answer is better, I think.

    – Alexey Romanov
    Nov 26 '18 at 10:37














5












5








5








In the metrics-scala library we have the following method:



def timer(name: String, scope: String = null): Timer


I want to deprecate the scope parameter and remove it from the next major version.



I tried this:



def timer(name: String): Timer
@deprecated(...)
def timer(name: String, scope: String): Timer


But that causes binary backward compatibility problems (see below *) already within the current major version.



I also tried this:



def timer(name: String, @deprecated(...) scope: String = null): Timer


But that gives warnings inside timer, and not for the caller of timer.



Did I miss something or is it really not possible to deprecate a parameter with default values?



(*) Mima report for option 1:



sbt:metrics4-scala-root> mimaReportBinaryIssues
[error] * synthetic method timer$default$2()java.lang.String in class nl.grons.metrics4.scala.MetricBuilder does not have a correspondent in current version
[error] filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("nl.grons.metrics4.scala.MetricBuilder.timer$default$2")









share|improve this question
















In the metrics-scala library we have the following method:



def timer(name: String, scope: String = null): Timer


I want to deprecate the scope parameter and remove it from the next major version.



I tried this:



def timer(name: String): Timer
@deprecated(...)
def timer(name: String, scope: String): Timer


But that causes binary backward compatibility problems (see below *) already within the current major version.



I also tried this:



def timer(name: String, @deprecated(...) scope: String = null): Timer


But that gives warnings inside timer, and not for the caller of timer.



Did I miss something or is it really not possible to deprecate a parameter with default values?



(*) Mima report for option 1:



sbt:metrics4-scala-root> mimaReportBinaryIssues
[error] * synthetic method timer$default$2()java.lang.String in class nl.grons.metrics4.scala.MetricBuilder does not have a correspondent in current version
[error] filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("nl.grons.metrics4.scala.MetricBuilder.timer$default$2")






scala






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 18:49







Erik van Oosten

















asked Nov 25 '18 at 9:48









Erik van OostenErik van Oosten

75479




75479













  • the first option should work. why are you saying it causes backwards compatibility=

    – pedrorijo91
    Nov 25 '18 at 9:57











  • Because Mima says so. I updated the question.

    – Erik van Oosten
    Nov 25 '18 at 18:47













  • A brute-force way would be to add a deprecated method def timer$default$2(): String = null. Though Oleg's answer is better, I think.

    – Alexey Romanov
    Nov 26 '18 at 10:37



















  • the first option should work. why are you saying it causes backwards compatibility=

    – pedrorijo91
    Nov 25 '18 at 9:57











  • Because Mima says so. I updated the question.

    – Erik van Oosten
    Nov 25 '18 at 18:47













  • A brute-force way would be to add a deprecated method def timer$default$2(): String = null. Though Oleg's answer is better, I think.

    – Alexey Romanov
    Nov 26 '18 at 10:37

















the first option should work. why are you saying it causes backwards compatibility=

– pedrorijo91
Nov 25 '18 at 9:57





the first option should work. why are you saying it causes backwards compatibility=

– pedrorijo91
Nov 25 '18 at 9:57













Because Mima says so. I updated the question.

– Erik van Oosten
Nov 25 '18 at 18:47







Because Mima says so. I updated the question.

– Erik van Oosten
Nov 25 '18 at 18:47















A brute-force way would be to add a deprecated method def timer$default$2(): String = null. Though Oleg's answer is better, I think.

– Alexey Romanov
Nov 26 '18 at 10:37





A brute-force way would be to add a deprecated method def timer$default$2(): String = null. Though Oleg's answer is better, I think.

– Alexey Romanov
Nov 26 '18 at 10:37












1 Answer
1






active

oldest

votes


















1














I believe (but I don't have MiMa setup now to check) that you can use traits:



object Foo extends DeprecatedFoo {
def timer(name: String): Unit = { println("called new shiny version") }
}

trait DeprecatedFoo {
@deprecated("", "")
def timer(name: String, scope: String = null) = { println("called bad old version")}
}

Foo.timer("xx") // calls new version
Foo.timer("xx", null) // calls old version and issues a warning:


The code compiled for old version would be doing invokevirtual Foo/timer(Ljava/lang/String;Ljava/lang/String;)Z, that would resolve to the old version too.






share|improve this answer
























  • This works! Mima is happy. Thanks Oleg!

    – Erik van Oosten
    Nov 26 '18 at 13:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466334%2fhow-to-deprecate-a-parameter-with-default-value-in-scala%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I believe (but I don't have MiMa setup now to check) that you can use traits:



object Foo extends DeprecatedFoo {
def timer(name: String): Unit = { println("called new shiny version") }
}

trait DeprecatedFoo {
@deprecated("", "")
def timer(name: String, scope: String = null) = { println("called bad old version")}
}

Foo.timer("xx") // calls new version
Foo.timer("xx", null) // calls old version and issues a warning:


The code compiled for old version would be doing invokevirtual Foo/timer(Ljava/lang/String;Ljava/lang/String;)Z, that would resolve to the old version too.






share|improve this answer
























  • This works! Mima is happy. Thanks Oleg!

    – Erik van Oosten
    Nov 26 '18 at 13:50
















1














I believe (but I don't have MiMa setup now to check) that you can use traits:



object Foo extends DeprecatedFoo {
def timer(name: String): Unit = { println("called new shiny version") }
}

trait DeprecatedFoo {
@deprecated("", "")
def timer(name: String, scope: String = null) = { println("called bad old version")}
}

Foo.timer("xx") // calls new version
Foo.timer("xx", null) // calls old version and issues a warning:


The code compiled for old version would be doing invokevirtual Foo/timer(Ljava/lang/String;Ljava/lang/String;)Z, that would resolve to the old version too.






share|improve this answer
























  • This works! Mima is happy. Thanks Oleg!

    – Erik van Oosten
    Nov 26 '18 at 13:50














1












1








1







I believe (but I don't have MiMa setup now to check) that you can use traits:



object Foo extends DeprecatedFoo {
def timer(name: String): Unit = { println("called new shiny version") }
}

trait DeprecatedFoo {
@deprecated("", "")
def timer(name: String, scope: String = null) = { println("called bad old version")}
}

Foo.timer("xx") // calls new version
Foo.timer("xx", null) // calls old version and issues a warning:


The code compiled for old version would be doing invokevirtual Foo/timer(Ljava/lang/String;Ljava/lang/String;)Z, that would resolve to the old version too.






share|improve this answer













I believe (but I don't have MiMa setup now to check) that you can use traits:



object Foo extends DeprecatedFoo {
def timer(name: String): Unit = { println("called new shiny version") }
}

trait DeprecatedFoo {
@deprecated("", "")
def timer(name: String, scope: String = null) = { println("called bad old version")}
}

Foo.timer("xx") // calls new version
Foo.timer("xx", null) // calls old version and issues a warning:


The code compiled for old version would be doing invokevirtual Foo/timer(Ljava/lang/String;Ljava/lang/String;)Z, that would resolve to the old version too.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 9:17









Oleg PyzhcovOleg Pyzhcov

4,5601821




4,5601821













  • This works! Mima is happy. Thanks Oleg!

    – Erik van Oosten
    Nov 26 '18 at 13:50



















  • This works! Mima is happy. Thanks Oleg!

    – Erik van Oosten
    Nov 26 '18 at 13:50

















This works! Mima is happy. Thanks Oleg!

– Erik van Oosten
Nov 26 '18 at 13:50





This works! Mima is happy. Thanks Oleg!

– Erik van Oosten
Nov 26 '18 at 13:50




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53466334%2fhow-to-deprecate-a-parameter-with-default-value-in-scala%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen