implements PR-13.5
This commit is contained in:
parent
a1f92375a6
commit
079db44cd1
@ -31,70 +31,94 @@ final class PbsFlowBodyAnalyzer {
|
||||
final var model = Model.from(ast, supplementalTopDecls);
|
||||
|
||||
for (final var topDecl : ast.topDecls()) {
|
||||
validateTopDecl(topDecl, model, diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateTopDecl(
|
||||
final PbsAst.TopDecl topDecl,
|
||||
final Model model,
|
||||
final DiagnosticSink diagnostics) {
|
||||
if (topDecl instanceof PbsAst.FunctionDecl functionDecl) {
|
||||
validateFunction(functionDecl, model, diagnostics);
|
||||
return;
|
||||
}
|
||||
if (topDecl instanceof PbsAst.StructDecl structDecl) {
|
||||
validateStruct(structDecl, model, diagnostics);
|
||||
return;
|
||||
}
|
||||
if (topDecl instanceof PbsAst.ServiceDecl serviceDecl) {
|
||||
validateService(serviceDecl, model, diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateFunction(
|
||||
final PbsAst.FunctionDecl functionDecl,
|
||||
final Model model,
|
||||
final DiagnosticSink diagnostics) {
|
||||
validateCallableBody(
|
||||
functionDecl.parameters(),
|
||||
functionDecl.body(),
|
||||
newCallableContext(
|
||||
typeOps.callableReturnType(
|
||||
functionDecl.returnKind(),
|
||||
functionDecl.returnType(),
|
||||
functionDecl.resultErrorType(),
|
||||
model),
|
||||
functionDecl.resultErrorType() == null ? null : functionDecl.resultErrorType().name(),
|
||||
errorName(functionDecl.resultErrorType()),
|
||||
null,
|
||||
model,
|
||||
diagnostics));
|
||||
continue;
|
||||
diagnostics);
|
||||
}
|
||||
if (topDecl instanceof PbsAst.StructDecl structDecl) {
|
||||
|
||||
private void validateStruct(
|
||||
final PbsAst.StructDecl structDecl,
|
||||
final Model model,
|
||||
final DiagnosticSink diagnostics) {
|
||||
final var receiverType = TypeView.struct(structDecl.name());
|
||||
for (final var method : structDecl.methods()) {
|
||||
validateCallableBody(
|
||||
method.parameters(),
|
||||
method.body(),
|
||||
newCallableContext(
|
||||
typeOps.callableReturnType(
|
||||
method.returnKind(),
|
||||
method.returnType(),
|
||||
method.resultErrorType(),
|
||||
model),
|
||||
method.resultErrorType() == null ? null : method.resultErrorType().name(),
|
||||
errorName(method.resultErrorType()),
|
||||
receiverType,
|
||||
model,
|
||||
diagnostics));
|
||||
diagnostics);
|
||||
}
|
||||
for (final var ctor : structDecl.ctors()) {
|
||||
validateCallableBody(
|
||||
ctor.parameters(),
|
||||
ctor.body(),
|
||||
newCallableContext(
|
||||
TypeView.unit(),
|
||||
null,
|
||||
receiverType,
|
||||
model,
|
||||
diagnostics));
|
||||
diagnostics);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (topDecl instanceof PbsAst.ServiceDecl serviceDecl) {
|
||||
|
||||
private void validateService(
|
||||
final PbsAst.ServiceDecl serviceDecl,
|
||||
final Model model,
|
||||
final DiagnosticSink diagnostics) {
|
||||
final var receiverType = TypeView.service(serviceDecl.name());
|
||||
for (final var method : serviceDecl.methods()) {
|
||||
validateCallableBody(
|
||||
method.parameters(),
|
||||
method.body(),
|
||||
newCallableContext(
|
||||
typeOps.callableReturnType(
|
||||
method.returnKind(),
|
||||
method.returnType(),
|
||||
method.resultErrorType(),
|
||||
model),
|
||||
method.resultErrorType() == null ? null : method.resultErrorType().name(),
|
||||
errorName(method.resultErrorType()),
|
||||
receiverType,
|
||||
model,
|
||||
diagnostics));
|
||||
}
|
||||
}
|
||||
diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,6 +137,29 @@ final class PbsFlowBodyAnalyzer {
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
private void validateCallableBody(
|
||||
final ReadOnlyList<PbsAst.Parameter> parameters,
|
||||
final PbsAst.Block body,
|
||||
final TypeView returnType,
|
||||
final String resultErrorName,
|
||||
final TypeView receiverType,
|
||||
final Model model,
|
||||
final DiagnosticSink diagnostics) {
|
||||
validateCallableBody(
|
||||
parameters,
|
||||
body,
|
||||
newCallableContext(
|
||||
returnType,
|
||||
resultErrorName,
|
||||
receiverType,
|
||||
model,
|
||||
diagnostics));
|
||||
}
|
||||
|
||||
private String errorName(final PbsAst.TypeRef errorType) {
|
||||
return errorType == null ? null : errorType.name();
|
||||
}
|
||||
|
||||
private void validateCallableBody(
|
||||
final ReadOnlyList<PbsAst.Parameter> parameters,
|
||||
final PbsAst.Block body,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user