leetgo icon indicating copy to clipboard operation
leetgo copied to clipboard

[Bug] wrong build with a struct includes a commented variable

Open FadingRose opened this issue 8 months ago • 1 comments

leetgo debug

Leetgo version info :

1.4.13
commit: f952219f2acc4498d2078ef14344d3a18c7451ca
built at: 2024-12-28T19:21:17Z
goos: linux
goarch: amd64

Home dir : /home/kobayakawaami/.config/leetgo Project root : /home/kobayakawaami/Code/my-leetcode Working dir : /home/kobayakawaami/Code/my-leetcode/go/0353.design-snake-game Project config file : /home/kobayakawaami/Code/my-leetcode/leetgo.yaml Project configuration:

# Leetgo configuration file, see more at https://github.com/j178/leetgo

# Your name
author: kobayakawaami
# Language of the question description: 'zh' (Simplified Chinese) or 'en' (English).
language: zh
code:
  # Language of code generated for questions: go, cpp, python, java... 
  # (will be overridden by command line flag -l/--lang).
  lang: go
  # The default template to generate filename (without extension), e.g. {{.Id}}.{{.Slug}}
  # Available attributes: Id, Slug, Title, Difficulty, Lang, SlugIsMeaningful
  # (Most questions have descriptive slugs, but some consist of random characters. The SlugIsMeaningful boolean indicates whether a slug is meaningful.)
  # Available functions: lower, upper, trim, padWithZero, toUnderscore, group.
  filename_template: '{{ .Id | padWithZero 4 }}{{ if .SlugIsMeaningful }}.{{ .Slug }}{{ end }}'
  # Generate question description into a separate question.md file, otherwise it will be embed in the code file.
  separate_description_file: true
  # Default modifiers for all languages.
  modifiers:
    - name: removeUselessComments
  go:
    # Base directory to put generated questions, defaults to the language slug, e.g. go, python, cpp.
    out_dir: go
    # Functions that modify the generated code.
    modifiers:
      - name: removeUselessComments
      - name: changeReceiverName
      - name: addNamedReturn
      - name: addMod
  python3:
    # Base directory to put generated questions, defaults to the language slug, e.g. go, python, cpp.
    out_dir: python
    # Path to the python executable that creates the venv.
    executable: python3
  cpp:
    # Base directory to put generated questions, defaults to the language slug, e.g. go, python, cpp.
    out_dir: cpp
    # C++ compiler
    cxx: g++
    # C++ compiler flags (our Leetcode I/O library implementation requires C++17).
    cxxflags: -O2 -std=c++17
  rust:
    # Base directory to put generated questions, defaults to the language slug, e.g. go, python, cpp.
    out_dir: rust
  java:
    # Base directory to put generated questions, defaults to the language slug, e.g. go, python, cpp.
    out_dir: java
leetcode:
  # LeetCode site, https://leetcode.com or https://leetcode.cn
  site: https://leetcode.cn
  # Credentials to access LeetCode.
  credentials:
    # How to provide credentials: browser, cookies, password or none.
    from:
      - browser
    # Browsers to get cookies from: chrome, safari, edge or firefox. If empty, all browsers will be tried. Only used when 'from' is 'browser'.
    browsers: [chrome]
contest:
  # Base directory to put generated contest questions.
  out_dir: contest
  # Template to generate filename of the question.
  filename_template: '{{ .ContestShortSlug }}/{{ .Id }}{{ if .SlugIsMeaningful }}.{{ .Slug }}{{ end }}'
  # Open the contest page in browser after generating.
  open_in_browser: true
# Editor settings to open generated files.
editor:
  # Use a predefined editor: vim, vscode, goland
  # Set to 'none' to disable, set to 'custom' to provide your own command and args.
  use: none
  # Custom command to open files.
  command: ""
  # Arguments to your custom command.
  # String contains {{.CodeFile}}, {{.TestFile}}, {{.DescriptionFile}}, {{.TestCasesFile}} will be replaced with corresponding file path.
  # {{.Folder}} will be substituted with the output directory.
  # {{.Files}} will be substituted with the list of all file paths.
  args: ""

Full configuration :

author: kobayakawaami
language: zh
code:
  lang: go
  filename_template: '{{ .Id | padWithZero 4 }}{{ if .SlugIsMeaningful }}.{{ .Slug }}{{ end }}'
  separate_description_file: true
  modifiers:
    - name: removeUselessComments
  go:
    out_dir: go
    modifiers:
      - name: removeUselessComments
      - name: changeReceiverName
      - name: addNamedReturn
      - name: addMod
  python3:
    out_dir: python
    executable: python3
  cpp:
    out_dir: cpp
    cxx: g++
    cxxflags: -O2 -std=c++17
  rust:
    out_dir: rust
  java:
    out_dir: java
leetcode:
  site: https://leetcode.cn
  credentials:
    from:
      - browser
    browsers:
      - chrome
contest:
  out_dir: contest
  filename_template: '{{ .ContestShortSlug }}/{{ .Id }}{{ if .SlugIsMeaningful }}.{{ .Slug }}{{ end }}'
  open_in_browser: true
editor:
  use: none
  command: ""
  args: ""

Debug log

✘ Runtime Error
                Passed cases:   ✔✔✘
fatal error: runtime: out of memory                                                                            
runtime stack:                                                                                                 
runtime.throw({0x4ee0a2?, 0x0?})                                                                               
panic.go, line 1067                                                                                            
runtime.sysMapOS(0xc02d800000, 0x400000)                                                                       
mem_linux.go, line 168                                                                                         
runtime.sysMap(0xc02d800000, 0x400000, 0x7ffc29c5f890?)                                                        
mem.go, line 155                                                                                               
runtime.(*mheap).grow(0x5c2600, 0xa?)                                                                          
mheap.go, line 1539                                                                                            
runtime.(*mheap).allocSpan(0x5c2600, 0xa, 0x0, 0x1)                                                            
mheap.go, line 1244                                                                                            
runtime.(*mheap).alloc.func1()                                                                                 
mheap.go, line 962                                                                                             
runtime.systemstack(0x471b9f)                                                                                  
    /usr/local/go/src/runtime/asm_amd64.s:514 +0x4a fp=0x7ffc29c5fa68 sp=0x7ffc29c5fa58 pc=0x46d58a            
runtime.systemstack_switch()                                                                                   
    /usr/local/go/src/runtime/asm_amd64.s:479 +0x8 fp=0xc00009da38 sp=0xc00009da28 pc=0x46d528                 
runtime.(*mheap).alloc(0x14000?, 0xa?, 0x0?)                                                                   
mheap.go, line 956                                                                                             
runtime.(*mcache).allocLarge(0x7f24ef344108?, 0x13880, 0x1)                                                    
mcache.go, line 234                                                                                            
runtime.mallocgc(0x13880, 0x4cfee0, 0x1)                                                                       
malloc.go, line 1177                                                                                           
runtime.makeslice(0xc0000a40a0?, 0x43?, 0x50?)                                                                 
slice.go, line 116                                                                                             
main.Constructor(...)                                                                                          
solution.go, line 27                                                                                           
main.(*DriverSolution).Helper_Constructor(0x4a647e?, {0xc0000144f0?, 0x4cf1a0?}, {0xc00005c500?, 0x3, 0xc?})   
solution.go, line 107                                                                                          
main.(*DriverSolution).Helper(0xc00009ddbe, {0xc00008a300, 0xd, 0x4ce7e0?}, {0xc000002300, 0xd, 0xc000014078?})
solution.go, line 144                                                                                          
main.main()                                                                                                    
solution.go, line 197                                                                                          
runtime.main()                                                                                                 
proc.go, line 272                                                                                              
runtime.goexit({})                                                                                             
    /usr/local/go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc00009dfe8 sp=0xc00009dfe0 pc=0x46f541                
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)                                                                   
proc.go, line 424                                                                                              
runtime.goparkunlock(...)                                                                                      
proc.go, line 430                                                                                              
runtime.forcegchelper()                                                                                        
proc.go, line 337                                                                                              
runtime.goexit({})                                                                                             
    /usr/local/go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000038fe8 sp=0xc000038fe0 pc=0x46f541                
created by runtime.init.7 in goroutine 1                                                                       
proc.go, line 325                                                                                              
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)                                                                   
proc.go, line 424                                                                                              
runtime.goparkunlock(...)                                                                                      
proc.go, line 430                                                                                              
runtime.bgsweep(0xc00005a000)                                                                                  
mgcsweep.go, line 277                                                                                          
runtime.gcenable.gowrap1()                                                                                     
mgc.go, line 203                                                                                               
runtime.goexit({})                                                                                             
    /usr/local/go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc0000397e8 sp=0xc0000397e0 pc=0x46f541                
created by runtime.gcenable in goroutine 1                                                                     
mgc.go, line 203                                                                                               
runtime.gopark(0xc00005a000?, 0x515a60?, 0x1?, 0x0?, 0xc000006fc0?)                                            
proc.go, line 424                                                                                              
runtime.goparkunlock(...)                                                                                      
proc.go, line 430                                                                                              
runtime.(*scavengerState).park(0x5b9880)                                                                       
mgcscavenge.go, line 425                                                                                       
runtime.bgscavenge(0xc00005a000)                                                                               
mgcscavenge.go, line 653                                                                                       
runtime.gcenable.gowrap2()                                                                                     
mgc.go, line 204                                                                                               
runtime.goexit({})                                                                                             
    /usr/local/go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc000039fe8 sp=0xc000039fe0 pc=0x46f541                
created by runtime.gcenable in goroutine 1                                                                     
mgc.go, line 204                                                                                               
runtime.runfinq()                                                                                              
mfinal.go, line 176                                                                                            
runtime.goexit({})                                                                                             
    /usr/local/go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc00003a7e8 sp=0xc00003a7e0 pc=0x46f541                
created by runtime.createfing in goroutine 1                                                                   
mfinal.go, line 163                                                                                            
runtime.gopark(0x5ba620?, 0xc0000387d0?, 0x85?, 0x78?, 0x5b06b0?)                                              
proc.go, line 424                                                                                              
runtime.gcBgMarkWorker(0xc0000742a0)                                                                           
mgc.go, line 1363                                                                                              
runtime.gcBgMarkStartWorkers.gowrap1()                                                                         
mgc.go, line 1279                                                                                              
runtime.goexit({})                                                                                             
    /usr/local/go/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc0000387e8 sp=0xc0000387e0 pc=0x46f541                
created by runtime.gcBgMarkStartWorkers in goroutine 1                                                         
mgc.go, line 1279

Description

type SnakeGame struct {
	snake   []Point
	blocked map[Point]bool

	food []Point
	// grid   [][]int // line 27
	width  int
	height int

	score int
}

func Constructor(width int, height int, food [][]int) SnakeGame {
	foodPoints := make([]Point, len(food))
	for i := range food {
		foodPoints[i] = Point{X: food[i][0], Y: food[i][1]}
	}

	grid := make([][]int, height)
	for i := range grid {
		grid[i] = make([]int, width)
	}

	return SnakeGame{
		snake:   []Point{{0, 0}},
		food:    foodPoints,
		score:   0,
		width:   width,
		height:  height,
		blocked: map[Point]bool{},
	}
}

SnakeGame.grid has been commentted, but the go test 353 failed and report:

main.Constructor(...)                                                                                          
solution.go, line 27                                                                                           

where indicates the commentted line.

This should be a leetgo bug rather than a go's one because the Constructor() can pass go unit test.

FadingRose avatar Mar 02 '25 13:03 FadingRose