Giter Club home page Giter Club logo

Comments (4)

laszlokindrat avatar laszlokindrat commented on May 28, 2024

@lattner can you please take a look?

from mojo.

VMois avatar VMois commented on May 28, 2024

I just saw that he provided an answer to my Discord question that I asked a few weeks ago (link - https://discord.com/channels/1087530497313357884/1190784717998538903/1196704091041185843).

As soon as new version of Mojo will be released I will check if this bug got fixed or not.

Thank you for your work.

from mojo.

lattner avatar lattner commented on May 28, 2024

yes, there is a bug here. We are doing the right thing non-trivial types, but trivial types like pointer are not handled correctly. This should be a compile time error:

fn main():
    var array = Pointer[Int]()
    _ = array^          ## Consumes the array variable
    _ = array[2]       ## Should be invalid to use "array" because it is consumed (would also crash at runtime in this case)

from mojo.

lattner avatar lattner commented on May 28, 2024

Ah, actually not. The real issue is that the transfer operation on a value of trivial type (like a pointer or integer) is actually a noop. It doesn't destroy the input value, because these things don't have copy constructors, move operators or the other stuff to track.

Thank you for filing this, this is pretty confusing. I filed the compiler to generate a warning to make this more clear:

x.mojo:4:14: warning: transfer from a value of trivial register type 'Pointer[Int, 0]' has no effect and can be removed
takePtr(array^)
                      ^

from mojo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.