Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Redeclaration and value assignment bug

Open TheMoxyFoxy opened this issue 5 years ago • 4 comments

Context

I am using a modified version of the Odin SDL Library. My fork is located here. My fork adds in functions for blitting, as well as fixing a non-relative import that breaks the library when not in shared.

This is the code I am using:

package main

import "lib:sdl"
import "lib:sdl/ttf"

//import "graphics"

main :: proc () {
    // returns zero on success else non-zero 
    if (sdl.init(sdl.Init_Flags.Everything) != 0) { 
        return;
    }

    win := sdl.create_window("Solis Luna",
                             cast(i32) sdl.Window_Pos.Centered,
                             cast(i32) sdl.Window_Pos.Centered,
                             1000, 1000,
                             sdl.Window_Flags.Shown);

    color := sdl.Color{255, 255, 255, 255};

    font := ttf.open_font("../fonts/Dynastium-Kjvy.ttf", 6);
    surface := ttf.render_glyph_solid(font, '@', cast(sdl.Color)color);

    win_surf := sdl.get_window_surface(win);

    sdl.blit_surface(cast(^sdl.Surface)surface, nil, win_surf, nil);

    for {
        continue;
    }
}

Here is a tree of my repository (with everything unnecessary removed):

+---lib
|   \---sdl
\---src
    \---main.odin

Here are the commands I am using to check and build the code: odin build src/main.odin -out:bin/solis-luna.exe -collection:lib=lib -llvm-api (ran in the top-level folder of the project) odin check $file -collection:lib=$project_path/lib -llvm-api -ignore-unknown-attributes -vet

Which the check turns into this when ran through Sublime on main.odin: odin check src/main.odin -collection:lib=D:/Solis-Luna/lib -llvm-api -ignore-unknown-attributes -vet

  • Operating System: Windows
  • Odin version/Commit: 51e50d3e318ce2588ce2d27c2af7ef6f11a0f02b

Expected Behavior

I am expecting this code to compile and display an @ on the screen. Whether or not the @ actually displays is to be determined, as I have been unable to build an executable.

Current Behavior

The compiler errors on redeclarations, which in this instance is ambiguous as to whether it means the foreign C function being declared in Odin or whether it thinks the function has been previously declared (which there is only one instance of each of these procedures). Here are the errors it gives:

D:/Solis-Luna/lib/sdl/sdl.odin(125:87) Redeclaration of foreign procedure 'SDL_GameControllerGetBindForAxis' with different type signatures
    at D:/Solis-Luna/lib/sdl/sdl.odin(125:50)
D:/Solis-Luna/lib/sdl/sdl.odin(126:91) Redeclaration of foreign procedure 'SDL_GameControllerGetBindForButton' with different type signatures
    at D:/Solis-Luna/lib/sdl/sdl.odin(126:52)
D:/Solis-Luna/lib/sdl/sdl.odin(465:56) Redeclaration of foreign procedure 'SDL_SetWindowShape' with different type signatures
    at D:/Solis-Luna/lib/sdl/sdl.odin(465:36)

The compiler also errors on two lines for types, one at surface := ttf.render_glyph_solid(font, '@', cast(sdl.Color)color); saying:

D:/Solis-Luna/src/main.odin(25:65) Cannot assign value 'color' of type 'Color' to 'Color' in argument
    Suggestion: the expression may be directly casted to type Color

Which in this case, for testing purposes, I have casted the sdl.Color previously declared to an sdl.Color, which is what the procedure takes and there is only one Color structure declared in the entirety of the library from what I could find. The compiler also gives a similar error on the line sdl.blit_surface(cast(^sdl.Surface)surface, nil, win_surf, nil);, but goes away with the cast(^sdl.Surface).

Steps to Reproduce

  1. Set up the project in a similar style
  2. Run the check or build command, adjusted to your folder locations
  3. It should give the same errors I have

Failure Logs

All errors that can be produced (includes removing the casts):

D:/Solis-Luna/lib/sdl/sdl.odin(125:87) Redeclaration of foreign procedure 'SDL_GameControllerGetBindForAxis' with different type signatures
        at D:/Solis-Luna/lib/sdl/sdl.odin(125:50)
D:/Solis-Luna/lib/sdl/sdl.odin(126:91) Redeclaration of foreign procedure 'SDL_GameControllerGetBindForButton' with different type signatures
        at D:/Solis-Luna/lib/sdl/sdl.odin(126:52)
D:/Solis-Luna/lib/sdl/sdl.odin(465:56) Redeclaration of foreign procedure 'SDL_SetWindowShape' with different type signatures
        at D:/Solis-Luna/lib/sdl/sdl.odin(465:36)
D:/Solis-Luna/src/main.odin(23:65) Cannot assign value 'color' of type 'Color' to 'Color' in argument
        Suggestion: the expression may be directly casted to type Color
D:/Solis-Luna/src/main.odin(27:22) Cannot assign value 'surface' of type '^Surface' to '^Surface' in argument

TheMoxyFoxy avatar Jul 04 '20 22:07 TheMoxyFoxy

Bump

TheMoxyFoxy avatar Jul 08 '20 22:07 TheMoxyFoxy

I ran into this bug as well this week. Attaching a repro to this comment. (Specifically a repro for the redefinition bug). You should see the error by just unzipping the .zip, and typing odin build . in the redefinition_bug_repro folder. redefinition_bug_repro.zip

bkaylor avatar Aug 04 '20 01:08 bkaylor

Hello!

I am marking this issue as stale as it has not received any engagement from the community or maintainers 120 days. That does not imply that the issue has no merit! If you feel strongly about this issue

  • open a PR referencing and resolving the issue;
  • leave a comment on it and discuss ideas how you could contribute towards resolving it;
  • leave a comment and describe in detail why this issue is critical for your use case;
  • open a new issue with updated details and a plan on resolving the issue.

The motivation for this automation is to help prioritize issues in the backlog and not ignore, reject, or belittle anyone..

github-actions[bot] avatar Jul 24 '22 21:07 github-actions[bot]

I could reproduce the redeclaration bug using @bkaylor's project. I could work around it by replacing the relative import "../" with import "../../sdl"

sgoeppert avatar Jul 25 '22 11:07 sgoeppert