Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit parameters should warn at call site in >= 3.7 #22441

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hamzaremmal
Copy link
Member

@hamzaremmal hamzaremmal commented Jan 23, 2025

Closes #22440

TODO:

  • Add test with -Wconf
  • Handle desugaring to generate valid code:
  abstract class Base(implicit config: Int)
  case class A(x: Int)(implicit config: Int) extends Base

should not be desugared to (anymore):

abstract class Base(implicit config: Int) extends Object() {
      private[this] implicit val config: Int
    }
    case class A(x: Int)(implicit config: Int) extends Test.Base()(config),
      _root_.scala.Product, _root_.scala.Serializable {
      val x: Int
      private[this] implicit val config: Int
      def copy(x: Int)(implicit config: Int): Test.A = new Test.A(x)(config)
      def copy$default$1: Int @uncheckedVariance = A.this.x
      def _1: Int = this.x
    }
    final lazy module val A: Test.A = new Test.A()
    final module class A() extends AnyRef() { this: Test.A.type =>
      def apply(x: Int)(implicit config: Int): Test.A = new Test.A(x)(config)
      def unapply(x$1: Test.A): Test.A = x$1
      override def toString: String = "A"
    }

but rather:

abstract class Base(implicit config: Int) extends Object() {
      private[this] implicit val config: Int
    }
    case class A(x: Int)(implicit config: Int) extends Test.Base()(using config),
      _root_.scala.Product, _root_.scala.Serializable {
      val x: Int
      private[this] implicit val config: Int
      def copy(x: Int)(implicit config: Int): Test.A = new Test.A(x)(using config)
      def copy$default$1: Int @uncheckedVariance = A.this.x
      def _1: Int = this.x
    }
    final lazy module val A: Test.A = new Test.A()
    final module class A() extends AnyRef() { this: Test.A.type =>
      def apply(x: Int)(implicit config: Int): Test.A = new Test.A(x)(using config)
      def unapply(x$1: Test.A): Test.A = x$1
      override def toString: String = "A"
    }

@hamzaremmal hamzaremmal requested a review from sjrd January 23, 2025 10:14
@hamzaremmal hamzaremmal enabled auto-merge January 23, 2025 10:15
@hamzaremmal hamzaremmal changed the title Implicit parameters should warn at call site under -source future Implicit parameters should warn at call site in >= 3.7 Jan 29, 2025
@hamzaremmal hamzaremmal added release-notes Should be mentioned in the release notes needs-minor-release This PR cannot be merged until the next minor release labels Jan 29, 2025
@hamzaremmal hamzaremmal force-pushed the i22440 branch 2 times, most recently from 52c9fa8 to 8b1be6d Compare January 29, 2025 19:06
if tp.companion == ImplicitMethodType && pt.applyKind != ApplyKind.Using && pt.args.nonEmpty then
val rewriteMsg = Message.rewriteNotice("This code", mversion.patchFrom)
report.errorOrMigrationWarning(
em"Implicit parameters should be provided with a `using` clause.$rewriteMsg",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also provide info how to disable the warning if someone wants to do it intentionally?

To disable the warning use -Wconf...

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we could and I will add it (I'm also planning to add a test with -Wconf).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@hamzaremmal hamzaremmal disabled auto-merge January 29, 2025 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-minor-release This PR cannot be merged until the next minor release release-notes Should be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implicit parameters should emit a warning under -source future at call site
3 participants