Skip to content

Commit ce14301

Browse files
Improve error handling for unresolved and unsupported interface methods in MLIRGenImpl (#302)
1 parent f89ffb0 commit ce14301

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

tslang/lib/TypeScript/MLIRGenInterfaces.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -469,20 +469,15 @@ namespace mlirgen
469469
}
470470
else
471471
{
472-
// a real, present, non-object-literal method (e.g. a class
473-
// implementing the interface) reaching the METHOD (not
474-
// methodsAsFields) branch - not yet exercised by any test.
475-
llvm_unreachable("not implemented yet");
476-
/*
477-
auto methodConstName = builder.create<mlir_ts::SymbolRefOp>(
478-
location, methodOrField.methodInfo.funcOp.getType(),
479-
mlir::FlatSymbolRefAttr::get(builder.getContext(),
480-
methodOrField.methodInfo.funcOp.getSymName()));
481-
482-
vtableValue =
483-
builder.create<mlir_ts::InsertPropertyOp>(location, virtTuple, methodConstName, vtableValue,
484-
MLIRHelper::getStructIndex(rewriter, fieldIndex));
485-
*/
472+
// unreachable: getInterfaceVirtualTableForObject (this function's
473+
// only caller of newInterfacePtr->getVirtualTable) hardcodes
474+
// methodsAsFields=true, so every entry in `virtualTable` is
475+
// guaranteed isField=true - this branch (a real method reaching
476+
// here as something other than a field) can never be taken for
477+
// an object's interface vtable. Fail gracefully rather than crash
478+
// in case that invariant is ever violated by a future caller.
479+
emitError(location, "interface method could not be resolved for this object");
480+
return TypeValueInitType{mlir::Type(), mlir::Value(), TypeProvided::Yes};
486481
}
487482

488483
fieldIndex++;
@@ -929,7 +924,13 @@ namespace mlirgen
929924
}
930925
else
931926
{
932-
llvm_unreachable("not implemented");
927+
// every interface-member SyntaxKind TypeScript's grammar allows
928+
// (PropertySignature, MethodSignature, ConstructSignature,
929+
// CallSignature, GetAccessor, SetAccessor, IndexSignature) is
930+
// handled above; fail gracefully rather than crash if some other
931+
// kind is ever produced here.
932+
emitError(location, "unsupported interface member");
933+
return mlir::failure();
933934
}
934935

935936
return mlir::success();

0 commit comments

Comments
 (0)