@@ -513,6 +513,17 @@ getCustomBuilderParams(std::initializer_list<MethodParameter> prefix,
513513 return builderParams;
514514}
515515
516+ static void errorIfPruned (size_t line, Method *m, const Twine &methodName,
517+ const AttrOrTypeDef &def) {
518+ if (m)
519+ return ;
520+ PrintFatalError (def.getLoc (), " Unexpected overlap when generating `" +
521+ methodName + " ` for " + def.getName () +
522+ " (from line " + Twine (line) + " )" );
523+ }
524+
525+ #define ERROR_IF_PRUNED (M, N, O ) errorIfPruned(__LINE__, M, N, O)
526+
516527void DefGen::emitCustomBuilder (const AttrOrTypeBuilder &builder) {
517528 // Don't emit a body if there isn't one.
518529 auto props = builder.getBody () ? Method::Static : Method::StaticDeclaration;
@@ -521,6 +532,10 @@ void DefGen::emitCustomBuilder(const AttrOrTypeBuilder &builder) {
521532 returnType = *builderReturnType;
522533 Method *m = defCls.addMethod (returnType, " get" , props,
523534 getCustomBuilderParams ({}, builder));
535+
536+ // If method is pruned, report error and terminate.
537+ ERROR_IF_PRUNED (m, " get" , def);
538+
524539 if (!builder.getBody ())
525540 return ;
526541
@@ -552,6 +567,10 @@ void DefGen::emitCheckedCustomBuilder(const AttrOrTypeBuilder &builder) {
552567 getCustomBuilderParams (
553568 {{" ::llvm::function_ref<::mlir::InFlightDiagnostic()>" , " emitError" }},
554569 builder));
570+
571+ // If method is pruned, report error and terminate.
572+ ERROR_IF_PRUNED (m, " getChecked" , def);
573+
555574 if (!builder.getBody ())
556575 return ;
557576
0 commit comments