Introduce special treatment for the blank identifier _

Mostly: Do not instantiate variables within for loops and allow
reusing differently typed blanks which previously wasn't possible.

This may be missing some corner-cases, but the added tests seem
to work as expected and nothing else fell apart it seems.
This commit is contained in:
Arne Welzel 2022-09-30 17:38:00 +02:00
parent 7f7c77ab07
commit 46334f8b59
21 changed files with 318 additions and 20 deletions

View file

@ -209,7 +209,7 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init,
init = expand_op(cast_intrusive<ListExpr>(init), init_t);
}
if ( id->GetType() )
if ( id->GetType() && ! id->IsBlank() )
{
if ( id->IsRedefinable() || (! init && attr && ! IsFunc(id->GetType()->Tag())) )
{
@ -247,7 +247,7 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init,
t = id->GetType();
}
if ( id->GetType() && id->GetType()->Tag() != TYPE_ERROR )
if ( id->GetType() && id->GetType()->Tag() != TYPE_ERROR && ! id->IsBlank() )
{
if ( dt != VAR_REDEF && (! init || ! do_init || (! t && ! (t = init_type(init)))) )
{