v2: fix fn call name lookup
							parent
							
								
									823b8ad244
								
							
						
					
					
						commit
						ea26b5f30c
					
				| 
						 | 
					@ -179,7 +179,6 @@ pub fn (c mut Checker) call_expr(call_expr ast.CallExpr) table.Type {
 | 
				
			||||||
	if fn_name == 'typeof' {
 | 
						if fn_name == 'typeof' {
 | 
				
			||||||
		return table.string_type
 | 
							return table.string_type
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	mut found := false
 | 
					 | 
				
			||||||
	// start hack: until v1 is fixed and c definitions are added for these
 | 
						// start hack: until v1 is fixed and c definitions are added for these
 | 
				
			||||||
	if fn_name == 'C.calloc' {
 | 
						if fn_name == 'C.calloc' {
 | 
				
			||||||
		return table.byteptr_type
 | 
							return table.byteptr_type
 | 
				
			||||||
| 
						 | 
					@ -193,17 +192,21 @@ pub fn (c mut Checker) call_expr(call_expr ast.CallExpr) table.Type {
 | 
				
			||||||
	// end hack
 | 
						// end hack
 | 
				
			||||||
	// look for function in format `mod.fn` or `fn` (main/builtin)
 | 
						// look for function in format `mod.fn` or `fn` (main/builtin)
 | 
				
			||||||
	mut f := table.Fn{}
 | 
						mut f := table.Fn{}
 | 
				
			||||||
	if f1 := c.table.find_fn(fn_name) {
 | 
						mut found := false
 | 
				
			||||||
		found = true
 | 
					 | 
				
			||||||
		f = f1
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// try prefix with current module as it would have never gotten prefixed
 | 
						// try prefix with current module as it would have never gotten prefixed
 | 
				
			||||||
	if !found && !fn_name.contains('.') {
 | 
						if !fn_name.contains('.') && !(c.file.mod.name in ['builtin', 'main']) {
 | 
				
			||||||
		if f1 := c.table.find_fn('${c.file.mod.name}.$fn_name') {
 | 
							if f1 := c.table.find_fn('${c.file.mod.name}.$fn_name') {
 | 
				
			||||||
			found = true
 | 
								found = true
 | 
				
			||||||
			f = f1
 | 
								f = f1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// already prefixed (mod.fn) or C/builtin/main
 | 
				
			||||||
 | 
						if !found {
 | 
				
			||||||
 | 
							if f1 := c.table.find_fn(fn_name) {
 | 
				
			||||||
 | 
								found = true
 | 
				
			||||||
 | 
								f = f1
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if !found {
 | 
						if !found {
 | 
				
			||||||
		c.error('unknown fn: $fn_name', call_expr.pos)
 | 
							c.error('unknown fn: $fn_name', call_expr.pos)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -641,6 +644,9 @@ pub fn (c mut Checker) ident(ident mut ast.Ident) table.Type {
 | 
				
			||||||
		if !name.contains('.') && !(c.file.mod.name in ['builtin', 'main']) {
 | 
							if !name.contains('.') && !(c.file.mod.name in ['builtin', 'main']) {
 | 
				
			||||||
			name = '${c.file.mod.name}.$ident.name'
 | 
								name = '${c.file.mod.name}.$ident.name'
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if name.contains('new_v') {
 | 
				
			||||||
 | 
								println(' ## $name - $c.file.path - $ident.pos.line_nr')
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		// println('# name: $name')
 | 
							// println('# name: $name')
 | 
				
			||||||
		// constant
 | 
							// constant
 | 
				
			||||||
		if constant := c.table.find_const(name) {
 | 
							if constant := c.table.find_const(name) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue