Skip to content

Add diagnostics for using auto as a type of variable and as function return type #348

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

Merged

Conversation

filipsajdak
Copy link
Contributor

While parsing the following code:

f: () -> auto = 42;

Rise an error with the following diagnostics:

error: to define a function f with deduced return type, write 'f : ( /* arguments / ) -> _ = { / function body */ }'

While parsing the following code:

i : auto = 42;

Rise an error with the following diagnostics:

error: to define a variable i with deduced type, write 'i := /* initializer */;'

All regression tests pass. Continuation of #342 (increasing QoI)

While parsing following code:
```cpp
f: () -> auto = 42;
```
Rise an error with the following diagnostics:
```
error: to define a function f with deduced return type, write 'f : ( /* arguments */ ) -> _ = { /* function body */ }'
```
While parsing the following code:
```cpp
i : auto = 42;
```
Rise an error with the following diagnostics:
```
error: to define a variable i with deduced type, write 'i := /* initializer */;'
```
@hsutter hsutter merged commit 0bac3bc into hsutter:main Apr 14, 2023
@hsutter
Copy link
Owner

hsutter commented Apr 14, 2023

Thanks! These are good helpful QoI diagnostics for common mistakes when coming from Cpp1 syntax, great stuff. 👍 🙏

@filipsajdak filipsajdak deleted the fsajdak-add-diagnostics-for-auto-use branch April 15, 2023 00:22
zaucy pushed a commit to zaucy/cppfront that referenced this pull request Dec 5, 2023
…return type (hsutter#348)

* Add diagnostics for using auto as function return type

While parsing following code:
```cpp
f: () -> auto = 42;
```
Rise an error with the following diagnostics:
```
error: to define a function f with deduced return type, write 'f : ( /* arguments */ ) -> _ = { /* function body */ }'
```

* Add diagnostics for using auto as a type of variable

While parsing the following code:
```cpp
i : auto = 42;
```
Rise an error with the following diagnostics:
```
error: to define a variable i with deduced type, write 'i := /* initializer */;'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants