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

infix usage of matchers #2036

Closed
Lasering opened this issue May 31, 2021 · 6 comments
Closed

infix usage of matchers #2036

Lasering opened this issue May 31, 2021 · 6 comments

Comments

@Lasering
Copy link

Lasering commented May 31, 2021

Under Scala 3 the usage of Matchers is severely hindered (when using the compiler flag -source future),by the error:

Alphanumeric method shouldBe is not declared `infix`; it should not be used as infix operator.
The operation can be rewritten automatically to `shouldBe` under -deprecation -rewrite.
Or rewrite to method syntax .shouldBe(...) manually.

Probably all methods in AnyShouldWrapper, and in ResultOf traits should be declared infix.

@bvenners
Copy link
Contributor

@Lasering Do you have a compiler flag set perhaps that gets you that warning? Infix uses of methods not marked infix are not supposed to be deprecated until 3.1, not 3.0.

scala> import org.scalatest.matchers.should.Matchers._

scala> 42 shouldBe > (8)
val res0: org.scalatest.Assertion = Succeeded

So for now you could perhaps turn off that flag, if you have one. If not let us know here. Meanwhile we will add those infix modifiers.

Bill

@Lasering
Copy link
Author

Lasering commented Feb 1, 2022

For those who want to compile code with scalacOptions: -Werror -source:future please add this option until this issue is resolved:

Test / scalacOptions += "-Wconf:msg=is not declared `infix`:s,msg=is declared 'open':s"

It also fixes the Unless class Any*Spec is declared 'open' errors.

@Lasering Lasering reopened this Feb 1, 2022
@Lasering
Copy link
Author

Lasering commented Feb 2, 2022

Scala 2.13.6 included a number of syntax changes were added to simplify cross-building between Scala 2 and 3. Especially (for this issue):

  • Allow soft keywords open and infix under -Xsource:3
  • Align leading infix operator with Scala 3 improvements

At least for Scala 2.13(.6) and Scala 3 the source can be the same, helping with the migration.

@cheeseng
Copy link
Contributor

cheeseng commented Aug 8, 2022

@Lasering We have added the open class for Any*Spec, I am not sure about the 2nd one 'Align leading infix operator with Scala 3 improvements', do you mind to clarify what we can do to improve this?

@Lasering
Copy link
Author

Lasering commented Aug 9, 2022

@cheeseng I quoted the wrong line from the 2.13.6 release notes. The right one is:

Allow soft keywords open and infix under -Xsource:3 (scala/scala#9580)

This allows you to declare most of the matchers methods as infix, and thus solve the problem described in the opening post.

@Lasering
Copy link
Author

Lasering commented Jan 9, 2023

Using scalatest 3.2.15 fixes this problem.

@Lasering Lasering closed this as completed Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants