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

[Syntax] Allow more type deduction cases #16

Open
SirLynix opened this issue Jun 21, 2022 · 0 comments
Open

[Syntax] Allow more type deduction cases #16

SirLynix opened this issue Jun 21, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@SirLynix
Copy link
Contributor

Currently, type deduction only occurs for variable declarations:

let x = 42.0;

is equivalent to

let x: f32 = 42.0;

It would be great to allow type deduction for other cases:

let x: f32;
let v = vec3(x, x, x); // no need to write vec3[f32](x, x, x)

Other examples:

let x: mat4[f32];
let y = mat3(x); //< okay, y is a mat3[f32]
let x: f32;
let a = array(x, x, x); // a is an array[f32, 3]
const vertPos = array[vec2[f32]](
	vec2(-1.0, 1.0), //< no need to write vec2[f32] for every value
	vec2(-1.0, -3.0),
	vec2( 3.0, 1.0)
);

It should also be pretty easy to add return type deduction (but i'm not sure it should be done):

fn foo() {} //< returns nothing
fn bar() { return 42; } //< return i32
fn foobar() { return vec3(1.0, 2.0, 3.0); } //< return vec3[f32]
@SirLynix SirLynix added the enhancement New feature or request label Jun 21, 2022
@SirLynix SirLynix changed the title [Feature] Allow more type deduction cases [Syntax] Allow more type deduction cases Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant