Repository: shader-slang/slang
File: source/slang/slang-session.cpp (C++)

Code before:

    DiagnosticSink sink(getSourceManager(), Lexer::sourceLocationLexer);
    applySettingsToDiagnosticSink(&sink, &sink, m_optionSet);

    // Attempting to create a "composite" of just one component type should
    // just return the component type itself, to avoid redundant work.
    //
    if (componentTypeCount == 1)
    {
        auto componentType = componentTypes[0];
        if (componentTypes == nullptr) {
            sink.diagnoseRaw(Severity::Error, "componentTypes[0] is nullptr\n");
            sink.getBlobIfNeeded(outDiagnostics);
            return SLANG_E_INVALID_ARG;
        }
        componentType->addRef();
        *outCompositeComponentType = componentType;
        return SLANG_OK;
    }

    List<RefPtr<ComponentType>> childComponents;
    for (Int cc = 0; cc < componentTypeCount; ++cc)
    {
        if (componentTypes[cc] == nullptr) {
            char infoBuffer[512];
            snprintf(infoBuffer, sizeof(infoBuffer), "componentTypes[%i] is nullptr\n", cc);
            sink.diagnoseRaw(Severity::Error, infoBuffer);
            sink.getBlobIfNeeded(outDiagnostics);
            return SLANG_E_INVALID_ARG;
        }
        childComponents.add(asInternal(componentTypes[cc]));
    }

    RefPtr<ComponentType> composite = CompositeComponentType::create(this, childComponents);

    sink.getBlobIfNeeded(outDiagnostics);

    *outCompositeComponentType = asExternal(composite.detach());
    return SLANG_OK;
}

SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL Linkage::specializeType(
    slang::TypeReflection* inUnspecializedType,
    slang::SpecializationArg const* specializationArgs,
    SlangInt specializationArgCount,
    ISlangBlob** outDiagnostics)
{
    SLANG_AST_BUILDER_RAII(getASTBuilder());

    auto unspecializedType = asInternal(inUnspecializedType);


Review comment (bug):
```
sink.diagnoseRaw(Severity::Error, StringUtil::makeStringWithFormat("componentTypes[%i] is nullptr\n", cc));
```

Code after:

    DiagnosticSink sink(getSourceManager(), Lexer::sourceLocationLexer);
    applySettingsToDiagnosticSink(&sink, &sink, m_optionSet);

    // Attempting to create a "composite" of just one component type should
    // just return the component type itself, to avoid redundant work.
    //
    if (componentTypeCount == 1)
    {
        auto componentType = componentTypes[0];
        if (componentType == nullptr)
        {
            sink.diagnose(SourceLoc{}, Diagnostics::nullComponentType, 0);
            sink.getBlobIfNeeded(outDiagnostics);
            return SLANG_E_INVALID_ARG;
        }
        componentType->addRef();
        *outCompositeComponentType = componentType;
        return SLANG_OK;
    }

    List<RefPtr<ComponentType>> childComponents;
    for (Int cc = 0; cc < componentTypeCount; ++cc)
    {
        if (componentTypes[cc] == nullptr)
        {
            sink.diagnose(SourceLoc{}, Diagnostics::nullComponentType, cc);
            sink.getBlobIfNeeded(outDiagnostics);
            return SLANG_E_INVALID_ARG;
        }
        childComponents.add(asInternal(componentTypes[cc]));
    }

    RefPtr<ComponentType> composite = CompositeComponentType::create(this, childComponents);

    sink.getBlobIfNeeded(outDiagnostics);

    *outCompositeComponentType = asExternal(composite.detach());
    return SLANG_OK;
}

SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL Linkage::specializeType(
    slang::TypeReflection* inUnspecializedType,
    slang::SpecializationArg const* specializationArgs,
    SlangInt specializationArgCount,
    ISlangBlob** outDiagnostics)
{
    SLANG_AST_BUILDER_RAII(getASTBuilder());

    auto unspecializedType = asInternal(inUnspecializedType);