<commit_before>package dyvil.tools.compiler.ast.statement;

import dyvil.collection.Entry;
import dyvil.collection.Map;
import dyvil.collection.iterator.ArrayIterator;
import dyvil.collection.mutable.IdentityHashMap;
import dyvil.tools.compiler.ast.context.CombiningContext;
import dyvil.tools.compiler.ast.context.IContext;
import dyvil.tools.compiler.ast.context.IDefaultContext;
import dyvil.tools.compiler.ast.context.ILabelContext;
import dyvil.tools.compiler.ast.expression.IValue;
import dyvil.tools.compiler.ast.expression.IValueList;
import dyvil.tools.compiler.ast.field.IDataMember;
import dyvil.tools.compiler.ast.field.IVariable;
import dyvil.tools.compiler.ast.field.Variable;
import dyvil.tools.compiler.ast.generic.ITypeContext;
import dyvil.tools.compiler.ast.statement.control.Label;
import dyvil.tools.compiler.ast.statement.loop.ILoop;
import dyvil.tools.compiler.ast.structure.IClassCompilableList;
import dyvil.tools.compiler.ast.type.IType;
import dyvil.tools.compiler.ast.type.Types;
import dyvil.tools.compiler.backend.MethodWriter;
import dyvil.tools.compiler.backend.exception.BytecodeException;
import dyvil.tools.compiler.config.Formatting;
import dyvil.tools.compiler.util.I18n;
import dyvil.tools.parsing.Name;
import dyvil.tools.parsing.ast.IASTNode;
import dyvil.tools.parsing.marker.Marker;
import dyvil.tools.parsing.marker.MarkerList;
import dyvil.tools.parsing.position.ICodePosition;

import java.util.Iterator;

public class StatementList implements IValue, IValueList, IDefaultContext, ILabelContext
{
	protected ICodePosition position;
	
	protected IValue[] values;
	protected int      valueCount;
	protected Label[]  labels;
	
	// Metadata
	protected Map<Name, Variable> variables;
	protected IType               returnType;
	
	public StatementList()
	{
		this.values = new IValue[3];
	}
	
	public StatementList(ICodePosition position)
	{
		this.position = position;
		this.values = new IValue[3];
	}
	
	@Override
	public ICodePosition getPosition()
	{
		return this.position;
	}
	
	@Override
	public void setPosition(ICodePosition position)
	{
		this.position = position;
	}
	
	@Override
	public void expandPosition(ICodePosition position)
	{
		this.position = this.position.to(position);
	}
	
	@Override
	public int valueTag()
	{
		return STATEMENT_LIST;
	}
	
	@Override
	public boolean isPrimitive()
	{
		return this.returnType != null && this.returnType.isPrimitive();
	}
	
	@Override
	public boolean isResolved()
	{
		return this.returnType != null && this.returnType.isResolved();
	}
	
	@Override
	public IType getType()
	{
		if (this.returnType != null)
		{
			return this.returnType;
		}
		if (this.valueCount == 0)
		{
			return this.returnType = Types.VOID;
		}
		return this.returnType = this.values[this.valueCount - 1].getType();
	}
	
	@Override
	public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context)
	{
		if (this.valueCount > 0)
		{
			IValue typed = this.values[this.valueCount - 1]
					.withType(type, typeContext, markers, new CombiningContext(this, context));
			if (typed != null)
			{
				this.values[this.valueCount - 1] = typed;
				this.returnType = typed.getType();
				return this;
			}<commit_msg>Fix isResolved for empty Statement Lists<commit_after>package dyvil.tools.compiler.ast.statement;

import dyvil.collection.Entry;
import dyvil.collection.Map;
import dyvil.collection.iterator.ArrayIterator;
import dyvil.collection.mutable.IdentityHashMap;
import dyvil.tools.compiler.ast.context.CombiningContext;
import dyvil.tools.compiler.ast.context.IContext;
import dyvil.tools.compiler.ast.context.IDefaultContext;
import dyvil.tools.compiler.ast.context.ILabelContext;
import dyvil.tools.compiler.ast.expression.IValue;
import dyvil.tools.compiler.ast.expression.IValueList;
import dyvil.tools.compiler.ast.field.IDataMember;
import dyvil.tools.compiler.ast.field.IVariable;
import dyvil.tools.compiler.ast.field.Variable;
import dyvil.tools.compiler.ast.generic.ITypeContext;
import dyvil.tools.compiler.ast.statement.control.Label;
import dyvil.tools.compiler.ast.statement.loop.ILoop;
import dyvil.tools.compiler.ast.structure.IClassCompilableList;
import dyvil.tools.compiler.ast.type.IType;
import dyvil.tools.compiler.ast.type.Types;
import dyvil.tools.compiler.backend.MethodWriter;
import dyvil.tools.compiler.backend.exception.BytecodeException;
import dyvil.tools.compiler.config.Formatting;
import dyvil.tools.compiler.util.I18n;
import dyvil.tools.parsing.Name;
import dyvil.tools.parsing.ast.IASTNode;
import dyvil.tools.parsing.marker.Marker;
import dyvil.tools.parsing.marker.MarkerList;
import dyvil.tools.parsing.position.ICodePosition;

import java.util.Iterator;

public class StatementList implements IValue, IValueList, IDefaultContext, ILabelContext
{
	protected ICodePosition position;
	
	protected IValue[] values;
	protected int      valueCount;
	protected Label[]  labels;
	
	// Metadata
	protected Map<Name, Variable> variables;
	protected IType               returnType;
	
	public StatementList()
	{
		this.values = new IValue[3];
	}
	
	public StatementList(ICodePosition position)
	{
		this.position = position;
		this.values = new IValue[3];
	}
	
	@Override
	public ICodePosition getPosition()
	{
		return this.position;
	}
	
	@Override
	public void setPosition(ICodePosition position)
	{
		this.position = position;
	}
	
	@Override
	public void expandPosition(ICodePosition position)
	{
		this.position = this.position.to(position);
	}
	
	@Override
	public int valueTag()
	{
		return STATEMENT_LIST;
	}
	
	@Override
	public boolean isPrimitive()
	{
		return this.returnType != null && this.returnType.isPrimitive();
	}
	
	@Override
	public boolean isResolved()
	{
		if (this.valueCount == 0)
		{
			return true;
		}
		return this.values[this.valueCount - 1].isResolved();
	}
	
	@Override
	public IType getType()
	{
		if (this.returnType != null)
		{
			return this.returnType;
		}
		if (this.valueCount == 0)
		{
			return this.returnType = Types.VOID;
		}
		return this.returnType = this.values[this.valueCount - 1].getType();
	}
	
	@Override
	public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context)
	{
		if (this.valueCount > 0)
		{
			IValue typed = this.values[this.valueCount - 1]
					.withType(type, typeContext, markers, new CombiningContext(this, context));
			if (typed != null)
			{
				this.values[this.valueCount - 1] = typed;
				this.returnType = typed.getType();
				return this;
			}
{'fraction_non_alphanumeric': 0.10857846912059141, 'fraction_numerical': 0.0030802402587401818, 'mean_word_length': 4.574248927038626, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1694069', 'n_tokens_mistral': 2223, 'n_tokens_neox': 2068, 'n_words': 401}