package dyvil.tools.compiler.ast.type.typevar;

import dyvil.annotation.Reified;
import dyvil.tools.compiler.ast.context.IContext;
import dyvil.tools.compiler.ast.generic.ITypeParameter;
import dyvil.tools.compiler.ast.generic.Variance;
import dyvil.tools.compiler.util.Markers;
import dyvil.tools.parsing.marker.MarkerList;
import dyvil.tools.parsing.position.ICodePosition;

public class ResolvedTypeVarType extends TypeVarType
{
	protected ICodePosition position;

	public ResolvedTypeVarType(ICodePosition position)
	{
		this.position = position;
	}

	public ResolvedTypeVarType(ITypeParameter typeParameter, ICodePosition position)
	{
		super(typeParameter);
		this.position = position;
	}

	@Override
	public ICodePosition getPosition()
	{
		return this.position;
	}

	@Override
	public void setPosition(ICodePosition position)
	{
		this.position = position;
	}

	@Override
	public void checkType(MarkerList markers, IContext context, int position)
	{
		super.checkType(markers, context, position);
		final Reified.Type reifiedKind = this.typeParameter.getReifiedKind();

		switch (position)
		{
		// the constants in this switch are the ones that only conditionally allow type var types
		case TypePosition.CLASS:
			if (reifiedKind != null)
			{
				return;
			}
			// Fallthrough
		case TypePosition.TYPE:
			if (reifiedKind == Reified.Type.TYPE)
			{
				return;
			}
			markers.add(Markers.semanticError(this.position, "type.var.class", this.typeParameter.getName()));
			return;
		case TypePosition.SUPER_TYPE:
			markers.add(Markers.semanticError(this.position, "type.var.super", this.typeParameter.getName()));
		}

		final Variance variance = this.typeParameter.getVariance();
		if ((position & TypePosition.NO_COVARIANT_FLAG) != 0 && variance == Variance.COVARIANT)
		{
			markers.add(Markers.semanticError(this.position, "type.var.covariant", this.typeParameter.getName()));
		}
		if ((position & TypePosition.NO_CONTRAVARIANT_FLAG) != 0 && variance == Variance.CONTRAVARIANT)
		{
			markers.add(Markers.semanticError(this.position, "type.var.contravariant", this.typeParameter.getName()));
		}
	}
}

@@ -1218,76 +1218,8 @@
 SS:%0A
-%09%09%09if (reifiedKind != null)%0A%09%09%09%7B%0A%09%09%09%09return;%0A%09%09%09%7D%0A%09%09%09// Fallthrough%0A
 %09%09ca
@@ -1263,28 +1263,15 @@
 ind 
-== Reified.Type.TYPE
+!= null
 )%0A%09%09
@@ -1290,16 +1290,34 @@
 n;%0A%09%09%09%7D%0A
+%09%09%09// Fallthrough%0A
 %09%09%09marke

Fix Type Parameter false negative