diff --git a/lib/std/collections/tuple.c3 b/lib/std/collections/tuple.c3 index d8869e844..efe59854d 100644 --- a/lib/std/collections/tuple.c3 +++ b/lib/std/collections/tuple.c3 @@ -1,6 +1,6 @@ module std::collections::tuple(); -struct Tuple +struct Tuple @deprecated { Type1 first; Type2 second; @@ -8,7 +8,7 @@ struct Tuple module std::collections::triple(); -struct Triple +struct Triple @deprecated { Type1 first; Type2 second; diff --git a/releasenotes.md b/releasenotes.md index 9da7c594c..7690e3ed4 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -8,6 +8,8 @@ ### Fixes - Issue where a lambda wasn't correctly registered as external. #1408 - Generic methods were incorrectly registered as functions, leading to naming collisions. #1402 +- Deprecated inline generic types. +- Deprecated tuple / triple types. ### Stdlib changes *None yet* diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 16f9f04ca..75872b149 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -296,6 +296,7 @@ struct TypeInfo_ ResolveStatus resolve_status : 3; TypeInfoKind kind : 6; bool optional : 1; + bool in_def : 1; TypeInfoCompressedKind subtype : 4; Type *type; SourceSpan span; diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 09a9cb829..bf3e861e3 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -1382,6 +1382,7 @@ static inline bool sema_analyse_typedef(SemaContext *context, Decl *decl, bool * return true; } TypeInfo *info = decl->typedef_decl.type_info; + info->in_def = true; if (!sema_resolve_type_info(context, info, RESOLVE_TYPE_DEFAULT)) return false; decl->type->canonical = info->type->canonical; // Do we need anything else? @@ -1404,6 +1405,7 @@ static inline bool sema_analyse_distinct(SemaContext *context, Decl *decl, bool // Infer the underlying type normally. TypeInfo *info = decl->distinct; + info->in_def = true; if (!sema_resolve_type_info(context, info, RESOLVE_TYPE_DEFAULT)) return false; // Optional isn't allowed of course. diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index 8e169acc3..b35e4884f 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -362,6 +362,12 @@ INLINE bool sema_resolve_generic_type(SemaContext *context, TypeInfo *type_info) Decl *type = sema_analyse_parameterized_identifier(context, inner->unresolved.path, inner->unresolved.name, inner->span, type_info->generic.params); if (!decl_ok(type)) return false; type_info->type = type->type; + if (!context->current_macro && !type_info->in_def) + { + if (!compiler.context.silence_deprecation) SEMA_NOTE(type_info, "Direct generic type declarations outside of macros is a deprecated feature, please use 'def' to create an alias."); + // TODO, completely disallow + // RETURN_SEMA_ERROR(type_info, "Direct generic type declarations are only allowed inside of macros. Use `def` to define an alias for the type instead."); + } return true; } diff --git a/test/unit/stdlib/atomic_types.c3 b/test/unit/stdlib/atomic_types.c3 index 42ef6d2f9..789f82e45 100644 --- a/test/unit/stdlib/atomic_types.c3 +++ b/test/unit/stdlib/atomic_types.c3 @@ -2,8 +2,10 @@ import std::thread; import std::io; import std::atomic::types; -Atomic() a; -Atomic() fa; +def AtomicUint = Atomic(); +def AtomicFloat = Atomic(); +AtomicUint a; +AtomicFloat fa; fn void! add() @test { diff --git a/test/unit/stdlib/collections/copy_map.c3 b/test/unit/stdlib/collections/copy_map.c3 index 913ff07ef..3fac5f3fd 100644 --- a/test/unit/stdlib/collections/copy_map.c3 +++ b/test/unit/stdlib/collections/copy_map.c3 @@ -2,6 +2,7 @@ module test; import std::io; import std::collections::map; +def IntMap = HashMap(); fn void! copy_map() @test { TrackingAllocator alloc; @@ -9,7 +10,7 @@ fn void! copy_map() @test assert(alloc.allocated() == 0); mem::@scoped(&alloc) { - HashMap() x; + IntMap x; x.new_init(); DString y; y.append("hello"); diff --git a/test/unit/stdlib/collections/list.c3 b/test/unit/stdlib/collections/list.c3 index cbb6af2c2..01e388a87 100644 --- a/test/unit/stdlib/collections/list.c3 +++ b/test/unit/stdlib/collections/list.c3 @@ -9,9 +9,10 @@ struct Overalign float[<4>] x @align(128); } +def OveralignList = List(); fn void overaligned_type() { - List() l; + OveralignList l; Overalign y; for (int i = 0; i < 1000; i++) l.push(y); assert((usz)l.get_ref(2) - (usz)l.get_ref(1) == Overalign.sizeof);