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.

Two escaped variables by ` can't be compiled when it is used with scalatest's

See original GitHub issue

Compiler version

This test reproduces with scalatest-3.2.10.

Compilers and results:

  • 2.11.12
  • 2.12.15
  • 2.13.7
  • 3.0.0
  • 3.0.1
  • 3.0.2
  • 3.1.0
  • 3.1.1-RC2

Minimized code

import org.scalatest._
import org.scalatest.matchers._

class BugTest extends wordspec.AnyWordSpec with should.Matchers {
  "can't compile" in {
    val `n1` = 42
    val `n2` = 44

    `n1` shouldBe `n1`
    `n2` shouldBe `n2`
  }

  "can compile 1" in {
    val `n1` = 42

    `n1` shouldBe `n1`
  }

  "can compile 2" in {
    val n1 = 42
    val n2 = 44

    n1 shouldBe n1
    n2 shouldBe n2
  }
}

Output

[error] -- Error: .../src/test/scala/BugTest.scala:10:4 
[error] 9 |    `n1` shouldBe `n1`
[error] 10 |    `n2` shouldBe `n2`
[error]    |    ^
[error]    |postfix operator `n2` needs to be enabled
[error]    |by making the implicit value scala.language.postfixOps visible.
[error]    |----
[error]    |This can be achieved by adding the import clause 'import scala.language.postfixOps'
[error]    |or by setting the compiler option -language:postfixOps.
[error]    |See the Scaladoc for value scala.language.postfixOps for a discussion
[error]    |why the feature needs to be explicitly enabled.

Suggested by compiler approach with adding postfixOps leads to this:

error] -- [E008] Not Found Error: .../src/test/scala/BugTest.scala:12:4 
[error] 11 |    `n1` shouldBe `n1`
[error] 12 |    `n2` shouldBe `n2`
[error]    |    ^
[error]    |    value n2 is not a member of org.scalatest.Assertion.
[error]    |    Note that `n2` is treated as an infix operator in Scala 3.
[error]    |    If you do not want that, insert a `;` or empty line in front
[error]    |    or drop any spaces behind the operator.
[error] -- [E051] Reference Error: .../src/test/scala/BugTest.scala:12:9 
[error] 12 |    `n2` shouldBe `n2`
[error]    |         ^^^^^^^^
[error]    |Ambiguous overload. The overloaded alternatives of method shouldBe in trait Matchers with types
[error]    | [T, U >: T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (resultOfAnWordApplication: 
[error]    |        org.scalatest.matchers.dsl.ResultOfAnWordToBePropertyMatcherApplication[
[error]    |          U
[error]    |        ]
[error]    |      )(implicit ev: T <:< AnyRef): org.scalatest.Assertion
[error]    | [T, U >: T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (resultOfAWordApplication: 
[error]    |        org.scalatest.matchers.dsl.ResultOfAWordToBePropertyMatcherApplication[U
[error]    |          ]
[error]    |      )(implicit ev: T <:< AnyRef): org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (bePropertyMatcher: org.scalatest.matchers.BePropertyMatcher[T])
[error]    |        (implicit ev: T <:< AnyRef): org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (resultOfAnWordApplication: 
[error]    |        org.scalatest.matchers.dsl.ResultOfAnWordToSymbolApplication
[error]    |      )(implicit toAnyRef: T <:< AnyRef): org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (resultOfAWordApplication: 
[error]    |        org.scalatest.matchers.dsl.ResultOfAWordToSymbolApplication
[error]    |      )(implicit toAnyRef: T <:< AnyRef): org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )(symbol: Symbol)(implicit toAnyRef: T <:< AnyRef): org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (resultOfSameInstanceAsApplication: 
[error]    |        org.scalatest.matchers.dsl.ResultOfTheSameInstanceAsApplication
[error]    |      )(implicit toAnyRef: T <:< AnyRef): org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )(right: Null)(implicit ev: T <:< AnyRef): org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (right: org.scalatest.matchers.dsl.DefinedWord)
[error]    |        (implicit definition: org.scalatest.enablers.Definition[T]): 
[error]    |          org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (right: org.scalatest.matchers.dsl.EmptyWord)
[error]    |        (implicit emptiness: org.scalatest.enablers.Emptiness[T]): 
[error]    |          org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (right: org.scalatest.matchers.dsl.WritableWord)
[error]    |        (implicit writability: org.scalatest.enablers.Writability[T]): 
[error]    |          org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (right: org.scalatest.matchers.dsl.ReadableWord)
[error]    |        (implicit readability: org.scalatest.enablers.Readability[T]): 
[error]    |          org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (anType: org.scalatest.matchers.dsl.ResultOfAnTypeInvocation[?]): 
[error]    |        org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (aType: org.scalatest.matchers.dsl.ResultOfATypeInvocation[?]): 
[error]    |        org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (right: org.scalatest.matchers.dsl.SortedWord)
[error]    |        (implicit sortable: org.scalatest.enablers.Sortable[T]): 
[error]    |          org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (spread: org.scalactic.TripleEqualsSupport.Spread[T]): 
[error]    |        org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )(beMatcher: org.scalatest.matchers.BeMatcher[T]): org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (comparison: 
[error]    |        org.scalatest.matchers.dsl.ResultOfGreaterThanOrEqualToComparison[T]
[error]    |      ): org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (comparison: 
[error]    |        org.scalatest.matchers.dsl.ResultOfLessThanOrEqualToComparison[T]
[error]    |      ): org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (comparison: org.scalatest.matchers.dsl.ResultOfGreaterThanComparison[T]
[error]    |        ): 
[error]    |      org.scalatest.Assertion
[error]    | [T]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )
[error]    |      (comparison: org.scalatest.matchers.dsl.ResultOfLessThanComparison[T]): 
[error]    |        org.scalatest.Assertion
[error]    | [T, R]
[error]    |  (leftSideValue: T)
[error]    |    (using pos: org.scalactic.source.Position, prettifier: 
[error]    |      org.scalactic.Prettifier
[error]    |    )(right: R)(implicit caneq: CanEqual[T, R]): org.scalatest.Assertion
[error]    |all match expected type <?>

Expectation

Should work on all tested compilers.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
pikinier20commented, Jan 10, 2022

@som-snytt In order to do some quick test, you may want to use scala-cli Having it in version 0.0.9, you just create file:

// using scala "3.1.2-RC1-bin-20220106-0b4c6e7-NIGHTLY"
// using lib "org.scalatest::scalatest:3.2.10"

import org.scalatest._
import org.scalatest.matchers._

class BugTest extends wordspec.AnyWordSpec with should.Matchers {
  "can't compile" in {
    val `n1` = 42
    val `n2` = 44

    `n1` shouldBe `n1`
    `n2` shouldBe `n2`
  }

  "can compile 1" in {
    val `n1` = 42

    `n1` shouldBe `n1`
  }

  "can compile 2" in {
    val n1 = 42
    val n2 = 44

    n1 shouldBe n1
    n2 shouldBe n2
  }
}

and run scala-cli test <filename>

0reactions
som-snyttcommented, Jan 10, 2022

@pikinier20 thanks! Sorry to bump the thread just for “thanks!”, but that is an especially good feature. I’ve meant to try scala-cli since I learned about it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

org.scalatest.funsuite.AnyFunSuite
By running each test in its own instance of the class, each test has its own copy of the instance variables, so you...
Read more >
ScalaTest Spec Compilation Error - Stack Overflow
It seems SBT tries to compile against scala 2.9.2. I guess you have to add one of scalaVersion := "2.10.4". or scalaVersion :=...
Read more >
Run/Debug Configuration: Scala Test | IntelliJ IDEA ...
All in package - select this option to run all Scala tests in the specified ... escape the double quotes using backslashes, for...
Read more >
Four ways to escape a cake - Typelevel
Let the Scala compiler work for you. We provide type classes, instances, conversions, testing, supplements to the standard library, ...
Read more >
2. Working with Data: Literals, Values, Variables, and Types
In this chapter we will cover the core data and variable types in Scala. ... type to use to store data, it will...
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