Skip to content

cmd/compile: internal compiler error: untyped type mismatch, have: untyped float, want: untyped int #41680

Closed

Description

@ianlancetaylor

On current tip (874b313, CL 247477) this valid code gets an incorrect compilation error.

I believe this is due to CL 255217. CC @cuonglm @mdempsky

package p

func F(s string) bool {
	const m = 16
	const n = 1e5
	_ = make([]int, n)
	return len(s) < n*m
}

Activity

  1. added this to the Go1.16 milestone on Sep 28, 2020
  2. ianlancetaylor commented on Sep 28, 2020

    @ianlancetaylor
    ContributorAuthor

    Sorry, I forgot to include the compilation error.

    foo.go:7:19: internal compiler error: untyped type mismatch, have: untyped float, want: untyped int
    
    goroutine 1 [running]:
    runtime/debug.Stack(0xd6b500, 0xc0000ba008, 0x0)
    	/home/iant/go/src/runtime/debug/stack.go:24 +0x9f
    cmd/compile/internal/gc.Fatalf(0xc73811, 0x29, 0xc0000cc620, 0x2, 0x2)
    	/home/iant/go/src/cmd/compile/internal/gc/subr.go:199 +0x1b0
    cmd/compile/internal/gc.setconst(0xc0003b6000, 0xc3bec0, 0xc0000a1ad0)
    	/home/iant/go/src/cmd/compile/internal/gc/const.go:981 +0x35c
    cmd/compile/internal/gc.evconst(0xc0003b6000)
    	/home/iant/go/src/cmd/compile/internal/gc/const.go:581 +0x785
    cmd/compile/internal/gc.typecheck1(0xc0003b6000, 0x2, 0x0)
    	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:2099 +0x2c5
    cmd/compile/internal/gc.typecheck(0xc0003b6000, 0x2, 0x0)
    	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:300 +0x735
    cmd/compile/internal/gc.typecheck1(0xc0003b6080, 0x12, 0x0)
    	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:593 +0x2c1c
    cmd/compile/internal/gc.typecheck(0xc0003b6080, 0x12, 0x0)
    	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:300 +0x735
    cmd/compile/internal/gc.typecheckslice(0xc0000ba448, 0x1, 0x1, 0x12)
    	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:118 +0x51
    cmd/compile/internal/gc.typecheckargs(0xc0003b6100)
    	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:2140 +0x96
    cmd/compile/internal/gc.typecheck1(0xc0003b6100, 0x1, 0x0)
    	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:2036 +0xa94e
    cmd/compile/internal/gc.typecheck(0xc0003b6100, 0x1, 0x0)
    	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:300 +0x735
    cmd/compile/internal/gc.typecheckslice(0xc0003a1a80, 0x4, 0x4, 0x1)
    	/home/iant/go/src/cmd/compile/internal/gc/typecheck.go:118 +0x51
    cmd/compile/internal/gc.Main(0xc81008)
    	/home/iant/go/src/cmd/compile/internal/gc/main.go:624 +0x2cb0
    main.main()
    	/home/iant/go/src/cmd/compile/main.go:52 +0xb1
    
  3. self-assigned this
    on Sep 28, 2020
  4. mdempsky commented on Sep 28, 2020

    @mdempsky
    Contributor

    Thanks. Looks like this is related to a pre-existing type-checking bug related to make. For example, this program is valid and type checks with gccgo and go/types, but not with Go 1.15:

    package main
    
    func main() {
    	const n = 1e5
    	_ = make([]int, n)
    	f := n
    	var _ float64 = f
    }
    

    Edit: Go 1.15's error message is:

    x.go:7:6: cannot use f (type int) as type float64 in assignment
    

    (Positively, it successfully compiles at tip, likely thanks to CL 255217.)

  5. cuonglm commented on Sep 28, 2020

    @cuonglm
    Member

    @mdempsky Is it normal that const n = 1e5 is untyped float, but the n.Val().Ctype() is CTINT?

  6. mdempsky commented on Sep 28, 2020

    @mdempsky
    Contributor

    @cuonglm No, that's the issue. If a Node has type Idealfloat, then it should have value CTFLT.

  7. cuonglm commented on Sep 28, 2020

    @cuonglm
    Member

    @cuonglm No, that's the issue. If a Node has type Idealfloat, then it should have value CTFLT.

    So I think that's the bug here. I can't find where we currently set that information. This bug does exists before CL 255217, it just works because we assign the value to n instead of doing assertion.

  8. mdempsky commented on Sep 28, 2020

    @mdempsky
    Contributor

    @cuonglm That's my assessment too. I have a fix. Will upload shortly.

  9. gopherbot commented on Sep 28, 2020

    @gopherbot
    Contributor

    Change https://golang.org/cl/257966 mentions this issue: cmd/compile: fix type checking of "make" arguments

  10. locked and limited conversation to collaborators on Sep 28, 2021
  11. added a commit that references this issue on Apr 29, 2024
    ad0ab81
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

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.release-blocker

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions