Skip to content

Commit 4cefbb1

Browse files
committed
[Sema] make printf a reserved function
1 parent 24ad78b commit 4cefbb1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/sema.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ Sema::resolveFunctionDecl(const FunctionDecl &function) {
666666
if (!function.params.empty())
667667
return report(function.location,
668668
"'main' function is expected to take no arguments");
669+
} else if (function.identifier == "printf") {
670+
return report(function.location,
671+
"'printf' is a reserved function name and cannot be used for "
672+
"user-defined functions");
669673
}
670674

671675
std::vector<std::unique_ptr<ResolvedParamDecl>> resolvedParams;

test/sema/printf_reserved.yl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: compiler %s -res-dump 2>&1 | filecheck %s
2+
3+
// CHECK: [[# @LINE + 1 ]]:1: error: 'printf' is a reserved function name and cannot be used for user-defined functions
4+
fn printf(): number {
5+
return 12345;
6+
}
7+
8+
fn main(): void {
9+
println(printf());
10+
}

0 commit comments

Comments
 (0)