Skip to content

cmd/compile: iota inside function in a ConstSpec is not accepted #22344

Closed

Description

@griesemer

https://play.golang.org/p/K0Vga-Y1fv reports an error, but the spec doesn't prohibit this code.
https://play.golang.org/p/MbPQO9FJku is accepted, and there is no reason why the former, with iota being declared in the universe block shouldn't also be accepted within the constant declaration.

Activity

  1. added this to the Go1.10 milestone on Oct 19, 2017
  2. griesemer commented on Oct 19, 2017

    @griesemer
    ContributorAuthor

    Not urgent in any way but marked as 1.10 so it doesn't slip from the radar. Might be an easy fix.

  3. zigo101 commented on Oct 20, 2017

    @zigo101
    Contributor

    There is a paradox

    package main
    
    import "unsafe"
    
    const (
    	i = 1
    	j
    	k
    	x = unsafe.Sizeof(func() {const a = iota; var _ [a-2]int }) // a is 0 or 3?
    	y
    	z
    )
    
    func main() {
    }

    The current gc thinks a is 0.

  4. mdempsky commented on Oct 20, 2017

    @mdempsky
    Contributor

    const a = iota sets a to 0.

  5. griesemer commented on Oct 20, 2017

    @griesemer
    ContributorAuthor

    @go101 This "paradox" was addressed with the most recent changes for #15550. The value of iota is the index of the respective ConstSpec in the constant declaration. Here you have a constant declaration inside the function, and the iota is in the first ConstSpec of that constant declaration, which has index 0. Hence the value of iota and thus a is 0.

  6. modified the milestones: Go1.10, Go1.11 on Oct 20, 2017
  7. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on May 31, 2018
  8. modified the milestones: Go1.11, Unplanned on May 31, 2018
  9. gopherbot commented on Sep 11, 2019

    @gopherbot
    Contributor

    Change https://golang.org/cl/194717 mentions this issue: cmd/compile: allow iota inside function in a ConstSpec

  10. locked and limited conversation to collaborators on Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions