Skip to content

Support getting source location - #102

Merged
liufengyun merged 4 commits into
mainfrom
source
Aug 29, 2026
Merged

Support getting source location#102
liufengyun merged 4 commits into
mainfrom
source

Conversation

@liufengyun

@liufengyun liufengyun commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Support getting source location

Summary

Support getting source and line positions to support testing and debugging:

import jo.compile.SourceLocation

def check(cond: Bool)(auto location: SourceLocation): Unit =
  if !cond then
    abort(location.file + ":" + location.line.toString + ": check failed")

check(answer == 42)

Checklist

  • Added / updated tests under tests/pos/ or tests/warn/
  • Docs updated if the change affects user-visible behavior
  • All commits are signed off (why?)
How to sign off commits

Use git commit -s to add the Signed-off-by line automatically:

To add a sign-off to the last commit retroactively:

git commit --amend -s --no-edit

To add sign-off to the last 3 commits:

git rebase --signoff HEAD~3

Security impact

No

Compatibility impact

Code that depend on the new API cannot use old standard library.

  • Source compatibility: existing code continue to compile
  • SAST compatibility
    • forward compatibility: new libraries can be used by old compiler
    • backward comopatibility: old libraries can be used by new compiler
  • Standard Library compatibility:
    • forward compatibility: new code can work with old stdlib
    • backward compatibility: old code work with the new stdlib
  • Runtime Library compatibility:
    • forward compatibility: new code can work with old runtime
    • backward compatibility: old code work with the new runtime
  • Build tool
    • Build spec compatibility: old projects continue to build
    • Joy package compatibility: old .joy can be consumed by new build tool

Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
Signed-off-by: Fengyun Liu <fengyun.liu.cs@gmail.com>
@liufengyun
liufengyun requested a review from everdance August 28, 2026 19:59
val newLocation = New(TypeTree(targetType)(span.point))(span.point)
val constructor = newLocation.select(Names.Constructor)
Some(constructor.appliedTo(
StringLit(Config.publishedSourcePath(source.file))(span.point),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

config?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can be confusing, the signature is as follows:

object Config
  def publishedSourcePath(file: String)(using config: Config): String = ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's really confusing

@liufengyun
liufengyun merged commit a79b7be into main Aug 29, 2026
3 checks passed
@liufengyun
liufengyun deleted the source branch August 29, 2026 20:59
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

Successfully merging this pull request may close these issues.

2 participants