| ... | @@ -1891,50 +1891,30 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc | ... | @@ -1891,50 +1891,30 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1891 | } | 1891 | } |
| 1892 | } | 1892 | } |
| 1893 | | 1893 | |
| 1894 | switch (type_entry->id) { | 1894 | if(!is_valid_param_type(type_entry)){ |
| 1895 | case ZigTypeIdInvalid: | 1895 | if(type_entry->id == ZigTypeIdOpaque){ |
| 1896 | zig_unreachable(); | 1896 | add_node_error(g, param_node->data.param_decl.type, |
| 1897 | case ZigTypeIdUnreachable: | 1897 | buf_sprintf("parameter of opaque type '%s' not allowed", buf_ptr(&type_entry->name))); |
| 1898 | case ZigTypeIdUndefined: | 1898 | } else { |
| 1899 | case ZigTypeIdNull: | | |
| 1900 | case ZigTypeIdOpaque: | | |
| 1901 | add_node_error(g, param_node->data.param_decl.type, | 1899 | add_node_error(g, param_node->data.param_decl.type, |
| 1902 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); | 1900 | buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); |
| 1903 | return g->builtin_types.entry_invalid; | 1901 | } |
| 1904 | case ZigTypeIdComptimeFloat: | 1902 | |
| 1905 | case ZigTypeIdComptimeInt: | 1903 | return g->builtin_types.entry_invalid; |
| 1906 | case ZigTypeIdEnumLiteral: | 1904 | } |
| 1907 | case ZigTypeIdBoundFn: | 1905 | |
| 1908 | case ZigTypeIdMetaType: | 1906 | switch (type_requires_comptime(g, type_entry)) { |
| 1909 | case ZigTypeIdVoid: | 1907 | case ReqCompTimeNo: |
| 1910 | case ZigTypeIdBool: | | |
| 1911 | case ZigTypeIdInt: | | |
| 1912 | case ZigTypeIdFloat: | | |
| 1913 | case ZigTypeIdPointer: | | |
| 1914 | case ZigTypeIdArray: | | |
| 1915 | case ZigTypeIdStruct: | | |
| 1916 | case ZigTypeIdOptional: | | |
| 1917 | case ZigTypeIdErrorUnion: | | |
| 1918 | case ZigTypeIdErrorSet: | | |
| 1919 | case ZigTypeIdEnum: | | |
| 1920 | case ZigTypeIdUnion: | | |
| 1921 | case ZigTypeIdFn: | | |
| 1922 | case ZigTypeIdVector: | | |
| 1923 | case ZigTypeIdFnFrame: | | |
| 1924 | case ZigTypeIdAnyFrame: | | |
| 1925 | switch (type_requires_comptime(g, type_entry)) { | | |
| 1926 | case ReqCompTimeNo: | | |
| 1927 | break; | | |
| 1928 | case ReqCompTimeYes: | | |
| 1929 | add_node_error(g, param_node->data.param_decl.type, | | |
| 1930 | buf_sprintf("parameter of type '%s' must be declared comptime", | | |
| 1931 | buf_ptr(&type_entry->name))); | | |
| 1932 | return g->builtin_types.entry_invalid; | | |
| 1933 | case ReqCompTimeInvalid: | | |
| 1934 | return g->builtin_types.entry_invalid; | | |
| 1935 | } | | |
| 1936 | break; | 1908 | break; |
| | 1909 | case ReqCompTimeYes: |
| | 1910 | add_node_error(g, param_node->data.param_decl.type, |
| | 1911 | buf_sprintf("parameter of type '%s' must be declared comptime", |
| | 1912 | buf_ptr(&type_entry->name))); |
| | 1913 | return g->builtin_types.entry_invalid; |
| | 1914 | case ReqCompTimeInvalid: |
| | 1915 | return g->builtin_types.entry_invalid; |
| 1937 | } | 1916 | } |
| | 1917 | |
| 1938 | FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index]; | 1918 | FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index]; |
| 1939 | param_info->type = type_entry; | 1919 | param_info->type = type_entry; |
| 1940 | param_info->is_noalias = param_node->data.param_decl.is_noalias; | 1920 | param_info->is_noalias = param_node->data.param_decl.is_noalias; |
| ... | @@ -2001,43 +1981,12 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc | ... | @@ -2001,43 +1981,12 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 2001 | } | 1981 | } |
| 2002 | } | 1982 | } |
| 2003 | | 1983 | |
| 2004 | switch (fn_type_id.return_type->id) { | 1984 | switch (type_requires_comptime(g, fn_type_id.return_type)) { |
| 2005 | case ZigTypeIdInvalid: | 1985 | case ReqCompTimeInvalid: |
| 2006 | case ZigTypeIdUndefined: | 1986 | return g->builtin_types.entry_invalid; |
| 2007 | case ZigTypeIdNull: | 1987 | case ReqCompTimeYes: |
| 2008 | case ZigTypeIdOpaque: | 1988 | return get_generic_fn_type(g, &fn_type_id); |
| 2009 | zig_unreachable(); | 1989 | case ReqCompTimeNo: |
| 2010 | | | |
| 2011 | case ZigTypeIdComptimeFloat: | | |
| 2012 | case ZigTypeIdComptimeInt: | | |
| 2013 | case ZigTypeIdEnumLiteral: | | |
| 2014 | case ZigTypeIdBoundFn: | | |
| 2015 | case ZigTypeIdMetaType: | | |
| 2016 | case ZigTypeIdUnreachable: | | |
| 2017 | case ZigTypeIdVoid: | | |
| 2018 | case ZigTypeIdBool: | | |
| 2019 | case ZigTypeIdInt: | | |
| 2020 | case ZigTypeIdFloat: | | |
| 2021 | case ZigTypeIdPointer: | | |
| 2022 | case ZigTypeIdArray: | | |
| 2023 | case ZigTypeIdStruct: | | |
| 2024 | case ZigTypeIdOptional: | | |
| 2025 | case ZigTypeIdErrorUnion: | | |
| 2026 | case ZigTypeIdErrorSet: | | |
| 2027 | case ZigTypeIdEnum: | | |
| 2028 | case ZigTypeIdUnion: | | |
| 2029 | case ZigTypeIdFn: | | |
| 2030 | case ZigTypeIdVector: | | |
| 2031 | case ZigTypeIdFnFrame: | | |
| 2032 | case ZigTypeIdAnyFrame: | | |
| 2033 | switch (type_requires_comptime(g, fn_type_id.return_type)) { | | |
| 2034 | case ReqCompTimeInvalid: | | |
| 2035 | return g->builtin_types.entry_invalid; | | |
| 2036 | case ReqCompTimeYes: | | |
| 2037 | return get_generic_fn_type(g, &fn_type_id); | | |
| 2038 | case ReqCompTimeNo: | | |
| 2039 | break; | | |
| 2040 | } | | |
| 2041 | break; | 1990 | break; |
| 2042 | } | 1991 | } |
| 2043 | | 1992 | |
| ... | @@ -2057,6 +2006,20 @@ bool is_valid_return_type(ZigType* type) { | ... | @@ -2057,6 +2006,20 @@ bool is_valid_return_type(ZigType* type) { |
| 2057 | zig_unreachable(); | 2006 | zig_unreachable(); |
| 2058 | } | 2007 | } |
| 2059 | | 2008 | |
| | 2009 | bool is_valid_param_type(ZigType* type) { |
| | 2010 | switch (type->id) { |
| | 2011 | case ZigTypeIdInvalid: |
| | 2012 | case ZigTypeIdUndefined: |
| | 2013 | case ZigTypeIdNull: |
| | 2014 | case ZigTypeIdOpaque: |
| | 2015 | case ZigTypeIdUnreachable: |
| | 2016 | return false; |
| | 2017 | default: |
| | 2018 | return true; |
| | 2019 | } |
| | 2020 | zig_unreachable(); |
| | 2021 | } |
| | 2022 | |
| 2060 | bool type_is_invalid(ZigType *type_entry) { | 2023 | bool type_is_invalid(ZigType *type_entry) { |
| 2061 | switch (type_entry->id) { | 2024 | switch (type_entry->id) { |
| 2062 | case ZigTypeIdInvalid: | 2025 | case ZigTypeIdInvalid: |