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

should ;s really be optional? #230

Open
MineBill opened this issue Jun 17, 2020 · 2 comments
Open

should ;s really be optional? #230

MineBill opened this issue Jun 17, 2020 · 2 comments
Labels
exp: low Achievable with little prior knowledge and guidance pri: low An issue with no impact to quality, performance, or functionality type: refactor Refactor existing code

Comments

@MineBill
Copy link

MineBill commented Jun 17, 2020

I have no idea how to call this issue, so if you think there a better name please change it.

Basically, while messing around with godot and mun, i figured out that this was possible:

// This compiles successfully and returns 999
pub fn random() -> i32 {
    2 2 2 2 2 2 2 2 2 999
}

Also this:

// Returns a, which is 0
pub fn random() -> i32 {
    let a = 0 a
}

// THIS DOESN'T COMPILE
pub fn random2() -> i32 {
    let a = a 0
}

And stuff like this:

// Returns 999
pub fn random() -> i32 {
    let a = 0 0 0 0 0 0 0 
    1 2 3 4 1 2 3 4 1 2 34 1 2 
    1.0 3.1 1 a 20 a a a a 999
}

So it looks like it's ignoring everything and returns what it's supposed to but i don't think you should be able to write anything like that.

@baszalmstra
Copy link
Collaborator

baszalmstra commented Jun 17, 2020

Hey @MineBill , this is actually all perfectly valid Mun code. The reason being that ;s are optional in Mun.

pub fn random() -> i32 {
    2 2 2 2 2 2 2 2 2 999
}

is parsed as

pub fn random() -> i32 {
    2; 2; 2; 2; 2; 2; 2; 2; 2; 999
}

since the last expression is the return expression, 999 is returned.

This:

// Returns a, which is 0
pub fn random() -> i32 {
    let a = 0 a
}

// THIS DOESN'T COMPILE
pub fn random2() -> i32 {
    let a = a 0
}

is parsed as:

// Returns a, which is 0
pub fn random() -> i32 {
    let a = 0; 
    a // a is the return expression 
}

// THIS DOESN'T COMPILE
pub fn random2() -> i32 {
    let a = a; // a is not yet defined in the initializer so this fails.
    0 // 0 is the return expression
}

I get the confusion though, would you prefer if ;s are not optional? Typescript also has optional ; but a new expression must reside on a newline, maybe that makes more sense?

@baszalmstra baszalmstra changed the title Weird parser issue? should ;s really be optional? Jun 17, 2020
@MineBill
Copy link
Author

MineBill commented Jun 17, 2020

I had no idea ; were optional. All of the examples used ;s and since Mun tries to look like Rust, i assumed ;s were required. I don't really have an opinion on whether ; should be optional or not but if the remain optional, i think that new expressions should reside on new lines. At the very least, ;s should be documented on the Book.

@baszalmstra baszalmstra added exp: low Achievable with little prior knowledge and guidance pri: low An issue with no impact to quality, performance, or functionality type: perf Changes that improve performance labels Jun 19, 2020
@Wodann Wodann added type: refactor Refactor existing code and removed type: perf Changes that improve performance labels Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exp: low Achievable with little prior knowledge and guidance pri: low An issue with no impact to quality, performance, or functionality type: refactor Refactor existing code
Projects
None yet
Development

No branches or pull requests

3 participants