Skip to content

compiler bug : string parameter misbehaves within for loop #396

Closed
@gopherbot

Description

@gopherbot

by kaushansky:

The following program doesn't compile, complains about unknown type 

func iterateFast(s string) int { 
  acc:=0; 
  for i:=0;i<10;i++ { 
    acc+=len(s); 
  } 
  return acc;  // fatal error: unknown etype 0/STRING 
} 

However, this variant compiles with no errors:

func iterateFast(s string) int { 
  s1:=s; 
  acc:=0; 
  for i:=0;i<10;i++ { 
    acc+=len(s1); 
  } 
  return acc;  // no problem
} 

I tried to localize the bug by removing for loop, but the following compiles just fine:
func iterateFast(s string) int { 
  acc:=0; 
  
  acc+=len(s); 
   
  return acc;  // no problem
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions