Skip to content

Conversation

@Manonox
Copy link

@Manonox Manonox commented Jan 8, 2026

Fixes: Facepunch/sbox-issues#9813
(Look there for details)

There's also a new test:

[TestMethod]
public void ObeyRecursiveGenericConstraints()
{
	var tl = new Sandbox.Internal.TypeLibrary();
	tl.AddAssembly( ThisAssembly, true );

	var goodboy = tl.GetType( typeof( ConstraintBreaker2<> ) )
								.CreateGeneric<ConstraintBreaker2TypeErased>( [typeof( ConstraintBreaker2Inner )] );
	Assert.IsNotNull( goodboy );

	var badboy = tl.GetType( typeof( ConstraintBreaker2<> ) )
								.CreateGeneric<ConstraintBreaker2TypeErased>( [typeof( TypeWrapper )] );
	Assert.IsNull( badboy );
}

public class ConstraintBreaker2Inner :
	IConstraintBreaker2<
		ConstraintBreaker2Inner,
		ConstraintBreaker2Inner,
		ConstraintBreaker2Inner
	>
{
	public void DoSomething( ConstraintBreaker2Inner value )
	{

	}

	public void DoSomething2( ConstraintBreaker2Inner value )
	{

	}

	public void DoSomething3( ConstraintBreaker2Inner value )
	{

	}
}

public class ConstraintBreaker2TypeErased { }

[Expose]
public class ConstraintBreaker2<T> : ConstraintBreaker2TypeErased where T : IConstraintBreaker2<T, T, T>
{
	public void DoSomething( T value )
	{
		value.DoSomething( value );
		value.DoSomething2( value );
		value.DoSomething3( value );
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeLibrary: MakeGenericType doesn't work correctly with generic parameter constraints

1 participant