Skip to main content
Version: Nightly

source_location

source_location() -> SourceLocation

Returns the location for where this function is called.

This currently doesn't work when called in a parameter expression.

Example:

from std.reflection import source_location

def log_message(msg: String):
var loc = source_location()
print("[", loc.file_name(), ":", loc.line(), "]", msg)

def main():
log_message("hello") # Prints: [ /path/to/file.mojo : 4 ] hello

Returns:

SourceLocation: The location information of the source_location() call.