Skip to content

[TRACKER] PR #360 #374

@jaibugbot

Description

@jaibugbot
Emailed In Reported Version Latest Broken Version Latest Broken Platforms Fix Version
beta-0.1.096 beta-0.2.010 windows, linux -

Description

compilers refuses to cast to `#as` field in case of builtin operators usage.

Buggy Code

#import "Basic";

#import "Compiler";

#run {
    set_build_options_dc(.{do_output = false});
    // When #as is used on a field with basic type, implicit casting occurs only when calling functions, but not when using operators:
    {
        A :: struct {
            #as x : int;
        }
        a := A.{10};
        max(1, a); // ok
        1 + a; // error        
    }
    // However, if the operator is overloaded, the cast succeeds:
    {
        A :: struct {
            x : int;
        }
        operator+ :: (a1 : A, a2 : A) {
        }
         
        B :: struct {
            #as a : A;
        }

        b := B.{.{10}};
        b + b; // ok
    } 
}
 
 
// I understand that this is because the operators for primitives are not actual functions, but i think it's worth reporting.

Workarounds

-

Latest Test Outputs


windows
Compiler Error Output

In Workspace 2 ("Target Program"):
C:/Users/Private/Desktop/testo_runner/_work/JaiCommunityBugTrackerDev/JaiCommunityBugTrackerDev/compiler_bugs/374_360_CEC0.jai:14,9: Error: Procedure call did not match any of the possible overloads.

    a := A.{10};
    max(1, a); // ok
    1 + a; // error
    ^^^^^

C:/Users/Private/Desktop/testo_runner/_work/JaiCommunityBugTrackerDev/JaiCommunityBugTrackerDev/compiler_bugs/374_360_CEC0.jai:14,9: The call site's argument types are: (s64/literal, A)

Possible overloads:

        
    operator + :: inline (a: S128, b: S128) -> S128 { // This can be the same code for S128 and U128.   (C:/jai/modules/Basic/Int128.jai:67)
                         ^^^^^^^^^^^^^^^^^^

        Type mismatch. Type wanted: S128; type given: s64.
        C:/jai/modules/Basic/Int128.jai:67,22: Info: ... in argument 1.
        
    operator + :: (a: U128, b: U128) -> U128 {   (C:/jai/modules/Basic/Int128.jai:745)
                  ^^^^^^^^^^^^^^^^^^

        Type mismatch. Type wanted: U128; type given: s64.
        C:/jai/modules/Basic/Int128.jai:745,15: Info: ... in argument 1.
        
    operator + :: (a: U128, b: u64) -> U128 {   (C:/jai/modules/Basic/Int128.jai:749)
                  ^^^^^^^^^^^^^^^^^

        Type mismatch. Type wanted: U128; type given: s64.
        C:/jai/modules/Basic/Int128.jai:749,15: Info: ... in argument 1.
        

linux
Compiler Error Output

In Workspace 2 ("Target Program"):
/home/ubuntu/Desktop/actions-runner/_work/JaiCommunityBugTrackerDev/JaiCommunityBugTrackerDev/compiler_bugs/374_360_CEC0.jai:14,9: Error: Procedure call did not match any of the possible overloads.

    a := A.{10};
    max(1, a); // ok
    1 + a; // error
    ^^^^^

/home/ubuntu/Desktop/actions-runner/_work/JaiCommunityBugTrackerDev/JaiCommunityBugTrackerDev/compiler_bugs/374_360_CEC0.jai:14,9: The call site's argument types are: (s64/literal, A)

Possible overloads:

        
    operator + :: inline (a: S128, b: S128) -> S128 { // This can be the same code for S128 and U128.   (/home/ubuntu/Desktop/Jai/jai-beta-0.2.010/modules/Basic/Int128.jai:67)
                         ^^^^^^^^^^^^^^^^^^

        Type mismatch. Type wanted: S128; type given: s64.
        /home/ubuntu/Desktop/Jai/jai-beta-0.2.010/modules/Basic/Int128.jai:67,22: Info: ... in argument 1.
        
    operator + :: (a: U128, b: U128) -> U128 {   (/home/ubuntu/Desktop/Jai/jai-beta-0.2.010/modules/Basic/Int128.jai:745)
                  ^^^^^^^^^^^^^^^^^^

        Type mismatch. Type wanted: U128; type given: s64.
        /home/ubuntu/Desktop/Jai/jai-beta-0.2.010/modules/Basic/Int128.jai:745,15: Info: ... in argument 1.
        
    operator + :: (a: U128, b: u64) -> U128 {   (/home/ubuntu/Desktop/Jai/jai-beta-0.2.010/modules/Basic/Int128.jai:749)
                  ^^^^^^^^^^^^^^^^^

        Type mismatch. Type wanted: U128; type given: s64.
        /home/ubuntu/Desktop/Jai/jai-beta-0.2.010/modules/Basic/Int128.jai:749,15: Info: ... in argument 1.
        


History V1

Version Windows Linux Mac
beta-0.2.010 ❌ - ExitCode 1 ❌ - ExitCode 1 -
beta-0.2.009 ❌ - ExitCode 1 ❌ - ExitCode 1 -
beta-0.2.008 ❌ - ExitCode 1 ❌ - ExitCode 1 -
beta-0.2.007 ❌ - ExitCode 1 ❌ - ExitCode 1 -
beta-0.2.006 ❌ - ExitCode 1 ❌ - ExitCode 1 -
beta-0.2.005 ❌ - ExitCode 1 ❌ - ExitCode 1 -
beta-0.2.004 ❌ - ExitCode 1 ❌ - ExitCode 1 -
beta-0.2.003 ❌ - ExitCode 1 ❌ - ExitCode 1 -
beta-0.2.002 ❌ - ExitCode 1 ❌ - ExitCode 1 -
beta-0.2.001 ❌ - ExitCode 1 ❌ - ExitCode 1 -
beta-0.1.096 ❌ - ExitCode 1 ❌ - ExitCode 1 -

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions