-
Notifications
You must be signed in to change notification settings - Fork 393
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 Declaration with Slice Type Compiles Without Error #2628
Milestone
Comments
In today's episode of "I Can't Believe This Actually Works"
…On Thu, 25 Jul 2024, at 01:15, 6h057 wrote:
Description:
*Issue Summary:*
eclaring a constant with a slice type should result in a compilation error, as slices are not valid constant types. However, the following code compiles and runs without error:
package main
func main() {
const b []string = []string{}
println("Hello", b)
}
*Expected Behavior:*
The code should not compile, and an error should be thrown indicating that slices cannot be used as constant types. This behavior is consistent with Go (Golang), where a similar code snippet results in an error stating `invalid constant type []string`.
*Actual Behavior:*
The code compiles and runs without any errors, printing "Hello" followed by the empty slice. This suggests that Gnolang does not enforce the expected type restrictions on constants.
—
Reply to this email directly, view it on GitHub <#2628>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABDW4XCZEZPMNE2HDPFKWO3ZOAYPRAVCNFSM6AAAAABLNNCYBSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQZDQNRRG42TMNA>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
7 tasks
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description:
Issue Summary:
Declaring a constant with a slice type should result in a compilation error, as slices are not valid constant types. However, the following code compiles and runs without error:
Expected Behavior:
The code should not compile, and an error should be thrown indicating that slices cannot be used as constant types. This behavior is consistent with Go (Golang), where a similar code snippet results in an error stating
invalid constant type []string
.Actual Behavior:
The code compiles and runs without any errors, printing "Hello" followed by the empty slice. This suggests that Gnolang does not enforce the expected type restrictions on constants.
The text was updated successfully, but these errors were encountered: