Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Jun 21, 2022
1 parent 9389247 commit 85d3262
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ private static void AppendLiteral(StoreObjectIdentifier storeObject, IndentedStr
.Append("DbFunction(").Append(code.Literal(storeObject.Name)).Append(")");
break;
default:
Check.DebugAssert(false, "Unexpected StoreObjectType: " + storeObject.StoreObjectType);
Check.DebugFail("Unexpected StoreObjectType: " + storeObject.StoreObjectType);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ protected virtual IReadOnlyList<MigrationOperation> Sort(
else
{
leftovers.Add(operation);
Check.DebugAssert(false, "Unexpected operation type: " + operation.GetType());
Check.DebugFail("Unexpected operation type: " + operation.GetType());
}
}

Expand Down Expand Up @@ -275,7 +275,7 @@ protected virtual IReadOnlyList<MigrationOperation> Sort(
}
else
{
Check.DebugAssert(false, "Operation removed twice: " + cyclicAddForeignKeyOperation);
Check.DebugFail("Operation removed twice: " + cyclicAddForeignKeyOperation);
}
}
Expand Down Expand Up @@ -2189,7 +2189,7 @@ private IEnumerable<MigrationOperation> GetDataOperations(

if (forSource)
{
Check.DebugAssert(false, "Insert using the source model");
Check.DebugFail("Insert using the source model");
break;
}

Expand All @@ -2212,7 +2212,7 @@ private IEnumerable<MigrationOperation> GetDataOperations(

if (forSource)
{
Check.DebugAssert(false, "Update using the source model");
Check.DebugFail("Update using the source model");
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public virtual Expression Expand(
return _visitedFromSqlExpressions[fromSql] = fromSql.Update(Expression.Constant(constantValues, typeof(object[])));

default:
Check.DebugAssert(false, "FromSql.Arguments must be Constant/ParameterExpression");
Check.DebugFail("FromSql.Arguments must be Constant/ParameterExpression");
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ public SqlServerGeometryMethodTranslator(
arguments.Where(e => typeof(Geometry).IsAssignableFrom(e.Type)));
var typeMapping = ExpressionExtensions.InferTypeMapping(geometryExpressions.ToArray());

Check.DebugAssert(typeMapping != null, "At least one argument must have typeMapping.");
if (typeMapping is null)
{
Check.DebugFail("At least one argument must have typeMapping.");
return null;
}

var storeType = typeMapping.StoreType;
var isGeography = string.Equals(storeType, "geography", StringComparison.OrdinalIgnoreCase);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public SqlServerNetTopologySuiteAggregateMethodTranslator(
return null;
}

if (sqlExpression.TypeMapping is not { } typeMapping)
{
Check.DebugFail("SQL expression is missing a type mapping.");
return null;
}

var functionName = method == GeometryCombineMethod
? "CollectionAggregate"
: method == UnionMethod
Expand All @@ -85,15 +91,12 @@ public SqlServerNetTopologySuiteAggregateMethodTranslator(
sqlExpression = new DistinctExpression(sqlExpression);
}

var storeType = sqlExpression.TypeMapping?.StoreType ?? "geometry";

return _sqlExpressionFactory.Function(
$"{storeType}::{functionName}",
// "geometry::" + functionName,
$"{typeMapping.StoreType}::{functionName}",
new[] { sqlExpression },
nullable: true,
argumentsPropagateNullability: new[] { false },
typeof(Geometry),
_typeMappingSource.FindMapping(typeof(Geometry), storeType));
method.ReturnType,
_typeMappingSource.FindMapping(method.ReturnType, typeMapping.StoreType));
}
}
8 changes: 4 additions & 4 deletions src/EFCore/Infrastructure/ModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected virtual void ValidateIgnoredMembers(
ignoredMember, entityType.DisplayName(), property.DeclaringEntityType.DisplayName()));
}

Check.DebugAssert(false, "Should never get here...");
Check.DebugFail("Should never get here...");
}

var navigation = entityType.FindNavigation(ignoredMember);
Expand All @@ -343,7 +343,7 @@ protected virtual void ValidateIgnoredMembers(
ignoredMember, entityType.DisplayName(), navigation.DeclaringEntityType.DisplayName()));
}

Check.DebugAssert(false, "Should never get here...");
Check.DebugFail("Should never get here...");
}

var skipNavigation = entityType.FindSkipNavigation(ignoredMember);
Expand All @@ -356,7 +356,7 @@ protected virtual void ValidateIgnoredMembers(
ignoredMember, entityType.DisplayName(), skipNavigation.DeclaringEntityType.DisplayName()));
}

Check.DebugAssert(false, "Should never get here...");
Check.DebugFail("Should never get here...");
}

var serviceProperty = entityType.FindServiceProperty(ignoredMember);
Expand All @@ -369,7 +369,7 @@ protected virtual void ValidateIgnoredMembers(
ignoredMember, entityType.DisplayName(), serviceProperty.DeclaringEntityType.DisplayName()));
}

Check.DebugAssert(false, "Should never get here...");
Check.DebugFail("Should never get here...");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ImmediateConventionScope(ConventionSet conventionSet, ConventionDispatche
}

public override void Run(ConventionDispatcher dispatcher)
=> Check.DebugAssert(false, "Immediate convention scope cannot be run again.");
=> Check.DebugFail("Immediate convention scope cannot be run again.");

public IConventionModelBuilder OnModelFinalizing(IConventionModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -716,7 +716,7 @@ public IConventionModelBuilder OnModelInitialized(IConventionModelBuilder modelB
if (navigationBuilder.Metadata.IsInModel
&& navigationBuilder.Metadata.FindAnnotation(name) != annotation)
{
Check.DebugAssert(false, "annotation removed");
Check.DebugFail("annotation removed");
return null;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Shared/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,9 @@ public static void DebugAssert([DoesNotReturnIf(false)] bool condition, string m
throw new Exception($"Check.DebugAssert failed: {message}");
}
}

[Conditional("DEBUG")]
[DoesNotReturn]
public static void DebugFail(string message)
=> throw new Exception($"Check.DebugAssert failed: {message}");
}

0 comments on commit 85d3262

Please sign in to comment.