Skip to content

Incorrect 'declaration is different' error with default parameters in states #14

@Racvol

Description

@Racvol

Describe the bug

Hello,

I've encountered a bug in the Papyrus compiler where it incorrectly flags function declarations as different between a script's empty state and a named state. This error occurs specifically when the function signature includes default parameters.

When two function declarations are textually identical and both use default parameters (e.g., bool force = false), the compiler throws a Checker error: declaration of the ... function in the ... state is different from the declaration in the empty state.

However, if the default parameter is removed from both declarations (e.g., bool force), making the parameter mandatory, the code compiles successfully. This demonstrates that the issue is not with the state system itself, but with how the compiler parses or compares signatures that contain default parameter syntax.

Thank you for your work.

Reproduction Steps

  1. Set up the VS Code Dev Container using the mcr.microsoft.com/devcontainers/cpp:ubuntu-24.04 image.

  2. Create the following Papyrus script file named TestDefaultParam.psc. This script contains two identical declarations of the Repair function, both using a default parameter.

    Scriptname TestDefaultParam
    
    function Repair(bool force = false)
        ; do nothing
    endFunction
    
    state AnimSlots
        function Repair(bool force = false)
            ; do nothing
        endFunction
    endState
  3. Attempt to compile it from the terminal within the container:

    papyrus compile -nocache -i Source/TestDefaultParam.psc -o dist/Scripts
  4. Observe the compilation failure with the following error:

    Source/TestDefaultParam.psc:8:5: Checker error: declaration of the Repair function in the AnimSlots state is different from the declaration in the empty state
        6 | 
        7 | state AnimSlots
        8 |     function Repair(bool force = false)
          |     ~~~~~~~~
        9 |         ; do nothing
       10 |     endFunction
    check files: 0.924 ms
    failed to compile files, 1 errors
    

Expected Behavior

The script TestDefaultParam.psc should compile successfully without any errors, as the function signatures for Repair are identical in both the empty state and the AnimSlots state.

Current Behavior

Checker error: declaration of the ... function in the ... state is different from the declaration in the empty state.

Additional Information/Context

The bug can be reliably bypassed by removing the default parameter from the function signatures. The following modified version of the script compiles correctly in the same environment:

  • Modified TestDefaultParam.psc (Compiles successfully)

    Scriptname TestDefaultParam
    
    function Repair(bool force)
        ; do nothing
    endFunction
    
    state AnimSlots
        function Repair(bool force)
            ; do nothing
        endFunction
    endState
  • Successful compilation output:

    finish 36.841 ms
    

This strongly suggests that the compiler's signature-matching logic for functions across different states does not correctly handle the = value part of the parameter declaration.

Compiler version

2025.03.18

Environment details (OS name and version, etc.)

The issue is consistently reproducible in the following clean, containerized environment:

  • IDE: Visual Studio Code with Dev Containers extension

  • Container Image: mcr.microsoft.com/devcontainers/cpp:ubuntu-24.04

  • Compiler: Command-line Papyrus compiler

  • Flags: -nocache

    FROM mcr.microsoft.com/devcontainers/cpp:ubuntu-24.04
    
    ENV DEBIAN_FRONTEND=noninteractive
    
    USER root
    
    RUN sed -i 's#http://archive.ubuntu.com#http://mirror.yandex.ru#' /etc/apt/sources.list.d/ubuntu.sources && \
        sed -i 's#http://security.ubuntu.com#http://mirror.yandex.ru#' /etc/apt/sources.list.d/ubuntu.sources
    
    RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        wget \
        cmake \
        ninja-build \
        git \
        gdb \
        rsync \
        sudo && \
        apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
    
    WORKDIR /workspaces/tools
    
    RUN wget -O papyrus-compiler.tar.gz https://github.com/russo-2025/papyrus-compiler/releases/download/2025.03.18/papyrus-compiler-ubuntu.tar.gz \
        && mkdir -p /workspaces/tools/papyrus-compiler \
        && tar -xzf papyrus-compiler.tar.gz -C /workspaces/tools/papyrus-compiler --strip-components=1 \
        && chmod +x /workspaces/tools/papyrus-compiler/papyrus \
        && rm papyrus-compiler.tar.gz
    
    ENV PATH="/workspaces/tools/papyrus-compiler:${PATH}"
    WORKDIR /workspaces/DeusTweaked
    USER vscode
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions