Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local functions #5624

Open
Ollhax opened this issue Nov 21, 2024 · 1 comment
Open

Local functions #5624

Ollhax opened this issue Nov 21, 2024 · 1 comment
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang kind:bug something doesn't work like it should

Comments

@Ollhax
Copy link

Ollhax commented Nov 21, 2024

Without checking the manual too closely I tried writing a local function like this:

float4 fragmentMain(VertexOutput vertex) : SV_Target
{
  static float GetValue(int val) { return val; } // Simplified example
  float a = GetValue(vertex.Input);

  // etc
}

So from what I understand this is not something that's actually supported, there's currently no support for local functions/lambda functions/closures/etc. But it still compiles into correct code - is this parsed as a member function? It has a few problems:

  • It crashes the language server in VS Code, i.e. code completion stops working.
  • When I tried to use a value from an outer function (thinking closures are supported) it compiled, but generated invalid GLSL.

Unless I'm completely off the mark here, declaring a function like GetValue inside a function should probably just produce an error.

@csyonghe
Copy link
Collaborator

Yes, this needs to produce an error.

@bmillsNV bmillsNV added this to the Q4 2024 (Fall) milestone Nov 21, 2024
@bmillsNV bmillsNV added kind:bug something doesn't work like it should goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang kind:bug something doesn't work like it should
Projects
None yet
Development

No branches or pull requests

3 participants