question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning when using @newtype in package object

See original GitHub issue

I have the following code:

package object stuff {
  @newtype case class Thing(underlying: Int)
}

In scala 2.12.x the following warning is issued (making -Xfatal-warning impossible):

[warn] package.scala:10: it is not recommended to define classes/objects inside of package objects.
[warn] If possible, define trait MetricActorRef__Types in package metrics instead.
[warn]   @newtype case class MetricActorRef(underlying: ActorRef)
[warn]    ^

This warning happens if I use any scala-newtype version > 0.2.1 (that’s the last version that works without the warning).

I am able to work around the issue by using https://github.com/ghik/silencer with the pathFilters pointing to the file in question (the @silent annotation does not work).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
joroKr21commented, Feb 11, 2019

Actually this library already uses version-dependent sources. Look for NewTypeCompatMacros.scala. You could just add a flag there emitTrait: Boolean or whatever and conditionally generate the trait.

I think it’s definitely worth doing that, not just because of the warning but also to reduce the overhead in terms of generated class files. 👍

0reactions
carymrobbinscommented, May 31, 2019

Fixed via #50.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Do I need to define functions when using newtype in Scala?
It seems simpler on the surface, but I'm still left scratching my head. I have this code: package com.craigtreptow.scrayz import io.estatico.
Read more >
More types - mypy 0.991 documentation
This section introduces a few additional kinds of types, including NoReturn , NewType , TypedDict , and types for async code. It also...
Read more >
autodoc issues with re-exporting NewType and using NewType with ...
Describe the bug The first issue is importing a re-exported NewType type ... correctly without manually setting the __qualname__ I get this: Warning, ......
Read more >
typing — Support for type hints — Python 3.11.1 documentation
Note that None as a type hint is a special case and is replaced by type(None) . NewType¶. Use the NewType helper to...
Read more >
go/types - Go Packages
Package types declares the data types and implements the algorithms for type-checking of Go packages. Use Config.Check to invoke the type checker for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found