mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
Deprecated inline generic types, deprecated tuple / triple types.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
module std::collections::tuple(<Type1, Type2>);
|
||||
|
||||
struct Tuple
|
||||
struct Tuple @deprecated
|
||||
{
|
||||
Type1 first;
|
||||
Type2 second;
|
||||
@@ -8,7 +8,7 @@ struct Tuple
|
||||
|
||||
module std::collections::triple(<Type1, Type2, Type3>);
|
||||
|
||||
struct Triple
|
||||
struct Triple @deprecated
|
||||
{
|
||||
Type1 first;
|
||||
Type2 second;
|
||||
|
||||
@@ -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*
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@ import std::thread;
|
||||
import std::io;
|
||||
import std::atomic::types;
|
||||
|
||||
Atomic(<uint>) a;
|
||||
Atomic(<float>) fa;
|
||||
def AtomicUint = Atomic(<uint>);
|
||||
def AtomicFloat = Atomic(<float>);
|
||||
AtomicUint a;
|
||||
AtomicFloat fa;
|
||||
|
||||
fn void! add() @test
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@ module test;
|
||||
import std::io;
|
||||
import std::collections::map;
|
||||
|
||||
def IntMap = HashMap(<String, int>);
|
||||
fn void! copy_map() @test
|
||||
{
|
||||
TrackingAllocator alloc;
|
||||
@@ -9,7 +10,7 @@ fn void! copy_map() @test
|
||||
assert(alloc.allocated() == 0);
|
||||
mem::@scoped(&alloc)
|
||||
{
|
||||
HashMap(<String, int>) x;
|
||||
IntMap x;
|
||||
x.new_init();
|
||||
DString y;
|
||||
y.append("hello");
|
||||
|
||||
@@ -9,9 +9,10 @@ struct Overalign
|
||||
float[<4>] x @align(128);
|
||||
}
|
||||
|
||||
def OveralignList = List(<Overalign>);
|
||||
fn void overaligned_type()
|
||||
{
|
||||
List(<Overalign>) 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);
|
||||
|
||||
Reference in New Issue
Block a user