fix linenumbers in failed assertion traces#380
Conversation
|
I tried this out manually using the example project in https://mill-build.org/mill/dev-1.0.0-RC2-68-43069c/scalalib/intro.html#_simple_scala_module. Updated to Scala 3.7.1 it reproduces the problem, but using a locally-published version of uTest built off of 8b07406 doesn't seem to fix it. Could you take a look and see if that's the case for you as well? |
my bad, assumed that assert is the last line - it should work now, PTAL |
|
Thanks! I tested it and it seems to work great. Will merge it and pay out the bounty using the same bank details as we used before |
/claim #354
There are two places that break line numbering:
1. Tracer. apply - betaReduce
compiler implementation of BetaReduce tries to convert Inlined terms using inlineContext - which seems to break positions
There are 2 ways to fix:
a - do not call betaReduce at all
b - transform Inlined with current Quotes context
I have chosen b - because it does a lesser logic change compared to b.
My implementation is equivalent to what Term.betaReduce does, with one difference that original Term.betaReduce computes inlineContext instead of directly using Quotes.
2. TestBuilder.testCallTreeExpr
Despite
assertexpression does have proper position attached to it, compiler for some reasons doesn't use it in generation of lineNumbersTable in class files.Wrapping it into
Inlinedterm fixes it.Honestly, I didn't dig into compiler internals to figure out how exactly it treats
Inlinedwhen generating LineNumberTable.However have seen lots of places where
Inlinedterms get some special treatment when it comes to spans (which are responsible for linenumbers and positions).Alternative is to manually control stack traces by editing StackTraceElements, which may be more flexible, I can implement it as well - just lmk which in your opinion is better way to go
Worth to mention:
If we use only
assertmacro then fix 1 is enough, however when we use bothTestandassertinside it - which is normal usecase of utest, then two fixes are needed.Inlined.copyorInlined.applyto have some influence on linenumbers, but its limited.changeOwnerdoesnt affect linennumber