compiler: detect and error on public init function & remove empty init functions
							parent
							
								
									065ce39577
								
							
						
					
					
						commit
						a06e2298f0
					
				| 
						 | 
					@ -222,6 +222,10 @@ fn (p mut Parser) fn_decl() {
 | 
				
			||||||
		f.name = p.check_name()
 | 
							f.name = p.check_name()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	f.fn_name_token_idx = p.cur_tok_index()
 | 
						f.fn_name_token_idx = p.cur_tok_index()
 | 
				
			||||||
 | 
						// init fn
 | 
				
			||||||
 | 
						if f.name == 'init' && f.is_public {
 | 
				
			||||||
 | 
							p.error('init function cannot be public')
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	// C function header def? (fn C.NSMakeRect(int,int,int,int))
 | 
						// C function header def? (fn C.NSMakeRect(int,int,int,int))
 | 
				
			||||||
	is_c := f.name == 'C' && p.tok == .dot
 | 
						is_c := f.name == 'C' && p.tok == .dot
 | 
				
			||||||
	// Just fn signature? only builtin.v + default build mode
 | 
						// Just fn signature? only builtin.v + default build mode
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,18 +4,13 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module http
 | 
					module http
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
#flag windows -I @VROOT/thirdparty/vschannel
 | 
					#flag windows -I @VROOT/thirdparty/vschannel
 | 
				
			||||||
#flag -l ws2_32
 | 
					#flag -l ws2_32, crypt32, secur32
 | 
				
			||||||
#flag -l crypt32
 | 
					 | 
				
			||||||
#flag -l secur32
 | 
					 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
#include "vschannel.c"
 | 
					#include "vschannel.c"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn C.new_tls_context() C.TlsContext
 | 
					fn C.new_tls_context() C.TlsContext
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn init() int { return 1 }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn (req &Request) ssl_do(port int, method, host_name, path string) ?Response {
 | 
					fn (req &Request) ssl_do(port int, method, host_name, path string) ?Response {
 | 
				
			||||||
	mut ctx := C.new_tls_context()
 | 
						mut ctx := C.new_tls_context()
 | 
				
			||||||
	C.vschannel_init(&ctx)
 | 
						C.vschannel_init(&ctx)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,8 +6,6 @@ module net
 | 
				
			||||||
#include <netdb.h>
 | 
					#include <netdb.h>
 | 
				
			||||||
#include <errno.h>
 | 
					#include <errno.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn init() int { return 1 }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn error_code() int {
 | 
					fn error_code() int {
 | 
				
			||||||
    return C.errno
 | 
					    return C.errno
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,13 +20,12 @@ const (
 | 
				
			||||||
	WSA_V22 = 0x202 // C.MAKEWORD(2, 2)
 | 
						WSA_V22 = 0x202 // C.MAKEWORD(2, 2)
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn init() int {
 | 
					fn init() {
 | 
				
			||||||
	mut wsadata := C.WSAData{}
 | 
						mut wsadata := C.WSAData{}
 | 
				
			||||||
	res := C.WSAStartup(WSA_V22, &wsadata)
 | 
						res := C.WSAStartup(WSA_V22, &wsadata)
 | 
				
			||||||
	if res != 0 {
 | 
						if res != 0 {
 | 
				
			||||||
		panic('socket: WSAStartup failed')
 | 
							panic('socket: WSAStartup failed')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return 1
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn error_code() int {
 | 
					fn error_code() int {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue