gopherjs / gopherjs/gopherjs

Compiler panic when computing array lengths

Open
#1,056 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
13.2k
Forks
573
PR merge metrics
No merged PRs in 30d

Description

I found following examples that cause the compiler to panic:

Example 1: [compiler panic] Unhandled len type: *types.Array

package main

func a() *[1]byte {
	println("side effect")
	return nil
}

func main() {
	println(len(*a()))
}

Example 2: [compiler panic] interface conversion: interface is int64, not int.

Note that return value of a() is no longer dereferenced.

package main

func a() *[1]byte {
	println("side effect")
	return nil
}

func main() {
	println(len(a()))
}

I expect there are similar problems with cap().

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files or tests are named in the issue. First reproduce both Go examples and inspect the compiler's handling of len for pointer-to-array values, then check the analogous cap path. Done means both examples compile without a panic and regression coverage verifies the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.