AcademySoftwareFoundation / AcademySoftwareFoundation/OpenShadingLanguage

Allow list initializer as function argument.

Open
#1,906 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.3k
Forks
414
Avg merge
3d 1h
Merged PRs (30d)
10

Description

### Problem

Initializer lists are not allowed as function arguments, would be nice if they were, and would possibly simplify some of the MaterialX code base for OSL code generation.

```
struct vector2
{
float x;
float y;
};

void NG_switch_vector2I(vector2 in1, vector2 in2, vector2 in3, output vector2 out)
{
out = in1;
}

shader test_shader
(
vector2 input = {1,2}, // this works
output float out = 0
)
{
vector2 outVec;
vector2 in1 = {0,1}; // this works

NG_switch_vector2I(
in1, // this works
vector2(0.000000, 0.000000), // this works
{0.000000, 0.000000}, // this doesn't work
outVec);

out = outVec.x;
}
```

**Expected behavior:**
I expected this to compile just fine...

**Actual behavior:**
But it didn't... I get the following compile error.
```
> oslc test.osl
test.osl:24: error: Cannot construct type 'unknown'
FAILED test.osl
```

### Steps to Reproduce

1. Compile the shader code above
2. Get compile error

### Versions

* OSL branch/version: 1.13.8.0
* OS: MacOS Sequoia
* C++ compiler:
* LLVM version: 17.0.6
* OIIO version: 2.5.9.0

Contributor guide

Open the contributing guide

Research direction

The reproducer is in test.osl and is compiled through oslc; start by running the reported command to confirm the diagnostic for the braced argument. Trace how the compiler handles the working initializer-list cases versus the function-call argument, then confirm that the example compiles successfully with the braced vector argument.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.