parent
							
								
									289e77d51b
								
							
						
					
					
						commit
						87934ecf39
					
				|  | @ -15,12 +15,12 @@ import v.depgraph | ||||||
| const ( | const ( | ||||||
| 	// NB: some of the words in c_reserved, are not reserved in C,
 | 	// NB: some of the words in c_reserved, are not reserved in C,
 | ||||||
| 	// but are in C++, or have special meaning in V, thus need escaping too.
 | 	// but are in C++, or have special meaning in V, thus need escaping too.
 | ||||||
| 	c_reserved     = ['auto', 'break', 'calloc', 'case', 'char', 'class', 'const', 'continue', | 	c_reserved     = ['array', 'auto', 'break', 'calloc', 'case', 'char', 'class', 'const', | ||||||
| 		'default', 'delete', 'do', 'double', 'else', 'enum', 'error', 'exit', 'export', 'extern', | 		'continue', 'default', 'delete', 'do', 'double', 'else', 'enum', 'error', 'exit', 'export', | ||||||
| 		'float', 'for', 'free', 'goto', 'if', 'inline', 'int', 'link', 'long', 'malloc', 'namespace', | 		'extern', 'float', 'for', 'free', 'goto', 'if', 'inline', 'int', 'link', 'long', 'malloc', | ||||||
| 		'new', 'panic', 'register', 'restrict', 'return', 'short', 'signed', 'sizeof', 'static', | 		'namespace', 'new', 'panic', 'register', 'restrict', 'return', 'short', 'signed', 'sizeof', | ||||||
| 		'struct', 'switch', 'typedef', 'typename', 'union', 'unix', 'unsigned', 'void', 'volatile', | 		'static', 'string', 'struct', 'switch', 'typedef', 'typename', 'union', 'unix', 'unsigned', | ||||||
| 		'while', 'template', 'stdout', 'stdin', 'stderr'] | 		'void', 'volatile', 'while', 'template', 'stdout', 'stdin', 'stderr'] | ||||||
| 	c_reserved_map = string_array_to_map(c_reserved) | 	c_reserved_map = string_array_to_map(c_reserved) | ||||||
| 	// same order as in token.Kind
 | 	// same order as in token.Kind
 | ||||||
| 	cmp_str        = ['eq', 'ne', 'gt', 'lt', 'ge', 'le'] | 	cmp_str        = ['eq', 'ne', 'gt', 'lt', 'ge', 'le'] | ||||||
|  | @ -1493,7 +1493,13 @@ fn (mut g Gen) stmt(node ast.Stmt) { | ||||||
| 			g.sql_stmt(node) | 			g.sql_stmt(node) | ||||||
| 		} | 		} | ||||||
| 		ast.StructDecl { | 		ast.StructDecl { | ||||||
| 			name := if node.language == .c { util.no_dots(node.name) } else { c_name(node.name) } | 			name := if node.language == .c { | ||||||
|  | 				util.no_dots(node.name) | ||||||
|  | 			} else if node.name in ['array', 'string'] { | ||||||
|  | 				node.name | ||||||
|  | 			} else { | ||||||
|  | 				c_name(node.name) | ||||||
|  | 			} | ||||||
| 			// TODO For some reason, build fails with autofree with this line
 | 			// TODO For some reason, build fails with autofree with this line
 | ||||||
| 			// as it's only informative, comment it for now
 | 			// as it's only informative, comment it for now
 | ||||||
| 			// g.gen_attrs(node.attrs)
 | 			// g.gen_attrs(node.attrs)
 | ||||||
|  |  | ||||||
|  | @ -0,0 +1,13 @@ | ||||||
|  | fn test_reserved_keywords_array_and_string() { | ||||||
|  | 	array := [1, 2, 3, 4] | ||||||
|  | 	mut res1 := array.map(it * 3) | ||||||
|  | 	mut res2 := array.filter(it > 2) | ||||||
|  | 	println(res1) | ||||||
|  | 	assert res1 == [3, 6, 9, 12] | ||||||
|  | 	println(res2) | ||||||
|  | 	assert res2 == [3, 4] | ||||||
|  | 
 | ||||||
|  | 	string := 'hello' | ||||||
|  | 	println(string) | ||||||
|  | 	assert string == 'hello' | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue