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

constant and results error #21609

Open
Eliyaan opened this issue May 30, 2024 · 4 comments
Open

constant and results error #21609

Eliyaan opened this issue May 30, 2024 · 4 comments
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).

Comments

@Eliyaan
Copy link
Contributor

Eliyaan commented May 30, 2024

Describe the bug

When a constant is used to initialize another constant using a function that returns a result (and propagating the result), it outputs an error.

Reproduction Steps

const constant = 5
const other = init_const(constant)!

fn main() {}

fn init_const(c int) !int {
    return c
}

Expected Behavior

To not have an error

Current Behavior

❯ v run .
main.v:2:35: error: to propagate the Result call, `ArrayFlags__static__zero` must return a Result
    1 | const constant = 5
    2 | const other = init_const(constant)!
      |                                   ^
    3 |
    4 | fn main() {}
Details: main.v:14:36: details: prepend ! before the declaration of the return type of `ArrayFlags__static__zero`
main.v:2:35: error: to propagate the call, `ArrayFlags__static__zero` must return a Result type
    1 | const constant = 5
    2 | const other = init_const(constant)!
      |                                   ^
    3 |
    4 | fn main() {}
Details: main.v:14:36: details: prepend ! before the declaration of the return type of `ArrayFlags__static__zero`

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.6 294f7e4.a4afcba

Environment details (OS name and version, etc.)

V full version: V 0.4.6 294f7e4.a4afcba
OS: linux, Linux version 6.7.11-200.fc39.x86_64 (mockbuild@bdb8d24f206645e2bda44c1cf867612d) (gcc (GCC) 13.2.1 20240316 (Red Hat 13.2.1-7), GNU ld version 2.40-14.fc39) #1 SMP PREEMPT_DYNAMIC Wed Mar 27 16:50:39 UTC 2024

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@Eliyaan Eliyaan added the Bug This tag is applied to issues which reports bugs. label May 30, 2024
@Eliyaan Eliyaan changed the title constant and results constant and results error May 30, 2024
@ttytm
Copy link
Member

ttytm commented May 30, 2024

I'd like to have this too. Funnily it works in some scenarios. Currently, spelling it out into or { panic(err) } is the reliable way.

@felipensp felipensp added Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones). Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Status: Confirmed This bug has been confirmed to be valid by a contributor. labels May 31, 2024
@felipensp
Copy link
Member

@spytheman It looks related to the p.codegen() scoping stuff.

@JalonSolov
Copy link
Contributor

Well, part of the problem is that you can't propagate from main - it is just an exit.

In the case of const, it's even before main, in _init().

@ttytm
Copy link
Member

ttytm commented May 31, 2024

Well, part of the problem is that you can't propagate from main - it is just an exit.

In the case of const, it's even before main, in _init().

It's right that the initialization of consts is different than in main. Still propagating from main (or without main in scripting mode) is the same as or { panic(err) }. So it should work for consts too. In my case, the scenarios where ! worked for consts, I think, were influenced by the sorting of the consts and if they were in different files of the same module. Unfortunately, I didn't make a report when running into this for time reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).
Projects
None yet
Development

No branches or pull requests

4 participants