From 9dfd5244ad2953753535e82acd05e72e5ab2bc5f Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 16 May 2025 10:42:11 -0700 Subject: Allow lambda exprs without captures to coerce to `functype`. (#7129) --- tests/language-feature/lambda/coerce-failure.slang | 19 +++++++++++++++++++ .../language-feature/lambda/coerce-to-functype.slang | 13 +++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/language-feature/lambda/coerce-failure.slang create mode 100644 tests/language-feature/lambda/coerce-to-functype.slang (limited to 'tests') diff --git a/tests/language-feature/lambda/coerce-failure.slang b/tests/language-feature/lambda/coerce-failure.slang new file mode 100644 index 000000000..a5286611c --- /dev/null +++ b/tests/language-feature/lambda/coerce-failure.slang @@ -0,0 +1,19 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv + + +func test(f: functype(int, int)->float) -> float +{ + return f(2,3) + 10.0f; +} + + +[numthreads(1,1,1)] +void computeMain() +{ + int c = 2; + // CHECK: ([[# @LINE+1]]): error 30019 + let result = test((int x, int y)=> x + y + c); + + // CHECK: ([[# @LINE+1]]): error 30019 + let result1 = test((int x, float y) => x + y); +} \ No newline at end of file diff --git a/tests/language-feature/lambda/coerce-to-functype.slang b/tests/language-feature/lambda/coerce-to-functype.slang new file mode 100644 index 000000000..9ec430def --- /dev/null +++ b/tests/language-feature/lambda/coerce-to-functype.slang @@ -0,0 +1,13 @@ +//TEST:INTERPRET(filecheck=CHECK): + +func test(f: functype(int, int)->float) -> float +{ + return f(2,3) + 10.0f; +} + +func main() +{ + let result = test((int x, int y)=>x+y); + // CHECK: 15.0 + printf("%f\n", result); +} \ No newline at end of file -- cgit v1.2.3