Skip to content

Commit 1f56e80

Browse files
authored
Merge pull request #78 from RelationalAI-oss/axb-derived-function-can-have-a-return-type-2026-01-14
Allow @derived function to have a return type annotation
2 parents 1a87808 + dfb472f commit 1f56e80

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/linting/extended_checks.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,11 @@ function check(t::ReturnTypeAnnotationRule, x::EXPR, markers::Dict{Symbol,String
889889
contains(markers[:filename], "test.jl") && return
890890
end
891891

892+
if haskey(markers, :macrocall)
893+
# return type annotation are mandatory in @derived functions
894+
contains(markers[:macrocall], "derived") && return
895+
end
896+
892897
msg = "Avoid return type annotations `function foo()::Type`. Return type annotations can hurt performance by forcing type conversions. [Explanation](https://github.com/RelationalAI/RAIStyle?tab=readme-ov-file#type-annotations)."
893898

894899
# Pattern: function name()::Type ... end (multiline)

test/rai_rules_tests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,22 @@ end
20902090
@test lint_test(source,
20912091
"Line 1, column 1: Avoid return type annotations")
20922092
end
2093+
2094+
@testset "one-liner without return type" begin
2095+
source = """
2096+
foo(x::Int) = string(x)
2097+
"""
2098+
@test !lint_has_error_test(source)
2099+
end
2100+
2101+
@testset "derived functions" begin
2102+
source = """
2103+
@derived v=1 function _is_ivm_frame(rt::Runtime, path::RelPath)::Bool
2104+
return RAI_BackIR.has_attr(definition_of(rt, path), :frame)
2105+
end
2106+
"""
2107+
@test !lint_has_error_test(source)
2108+
end
20932109
end
20942110

20952111
@testset "String concatenation with *" begin

0 commit comments

Comments
 (0)