Buggy code:
public class NameResolution { private final ModuleLoader loader ; private String filename ; private ModuleID module ; public NameResolution ( ModuleLoader loader ) { } public void resolve ( WhileyFile wf ) { ArrayList < Import > imports = new ArrayList < Import > ( ) ; module = wf . module ; filename = wf . filename ; imports . add ( new Import ( module . pkg ( ) , module . module ( ) , "*" ) ) ; imports . add ( new Import ( module . pkg ( ) , "*" ) ) ; for ( Decl d : wf . declarations ) { try { if ( d instanceof ImportDecl ) { ImportDecl impd = ( ( ImportDecl ) ( d ) ) ; <START_BUG> imports . add ( 0 , new Import ( new PkgID ( impd . pkg ) , impd . module , impd . name ) ) ; <END_BUG> } else if ( d instanceof FunDecl ) { resolve ( ( ( FunDecl ) ( d ) ) , imports ) ; } else if ( d instanceof TypeDecl ) { resolve ( ( ( TypeDecl ) ( d ) ) , imports ) ; } else if ( d instanceof ConstDecl ) { resolve ( ( ( ConstDecl ) ( d ) ) , imports ) ; } } catch ( ResolveError ex ) { syntaxError ( errorMessage ( RESOLUTION_ERROR , ex . getMessage ( ) ) , filename , d ) ; } } } protected void resolve ( ConstDecl td , ArrayList < Import > imports ) { } protected void resolve ( TypeDecl td , ArrayList < Import > imports ) throws ResolveError { } protected void resolve ( FunDecl fd , ArrayList < Import > imports ) { } public void resolve ( Stmt s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected void resolve ( Assign s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected void resolve ( Assert s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected void resolve ( Return s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected void resolve ( Debug s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected void resolve ( Throw s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected void resolve ( IfElse s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected void resolve ( Switch s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected void resolve ( TryCatch s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected void resolve ( While s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected void resolve ( For s , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected Expr resolve ( Expr e , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected Expr resolve ( Invoke ivk , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected Expr resolve ( UnknownVariable v , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected Expr resolve ( UnOp v , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected Expr resolve ( BinOp v , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected Expr resolve ( Convert c , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected Expr resolve ( ListAccess v , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) { } protected Expr resolve ( NaryOp v , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected Expr resolve ( Comprehension e , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected Expr resolve ( RecordGen sg , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected Expr resolve ( TupleGen sg , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected Expr resolve ( DictionaryGen sg , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected Expr resolve ( TypeConst tc , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { } protected Expr resolve ( FunConst tc , HashMap < String , Set < Expr > > environment , ArrayList < Import > imports ) throws ResolveError { }

Fix:
imports . add ( 1 , new Import ( new PkgID ( impd . pkg ) , impd . module , impd . name ) ) ;