asoffer / Icarus

An experimental general-purpose programming language
Apache License 2.0
9 stars 2 forks source link

Implicit casting is broken #26

Closed perimosocordiae closed 3 years ago

perimosocordiae commented 3 years ago

This came up when trying to work with the size of an array (foo:?.length) which has type nat64.

Reproducer:

$ cat demo.ic 
a: int64 = 1
b: nat64 = a

Observed:

$ ./icarus demo.ic
[140512805390176 compiler/emit/special.cc:224] Assertion failed
    Expected: type::Type(to.type()) == from.type()
         LHS: nat64
         RHS: int64
*** SIGABRT received at time=1606918096 ***
PC: @     0x7fcbafde48cb  (unknown)  raise
    @          0x14049be         48  absl::WriteFailureInfo()
    @          0x14046a2        224  absl::AbslFailureSignalHandler()
    @     0x7fcbb02fabb0  (unknown)  (unknown)
    @          0x1119e85         48  compiler::Compiler::EmitMoveAssign()
    @           0xeb62fc        112  compiler::Compiler::Visit()
    @           0xedfb0c         96  type::Visitor<>::ErasedVisit()::{lambda()#1}::operator()<>()
    @           0xedfa87         64  std::__invoke_impl<>()
    @           0xedfa37         64  std::__invoke<>()
    @           0xedf9d3         64  std::__apply_impl<>()
    @           0xedf972         48  std::apply<>()
    @           0xec1f9d         80  type::Visitor<>::ErasedVisit()
    @          0x13f18a9         64  type::Primitive::Accept()
    @           0xf5ec90        144  type::Visitor<>::Visit()
    @           0xf5eb30         96  compiler::Compiler::EmitMoveAssign()
    @           0xf5c523        144  compiler::Compiler::EmitMoveInit()
    @          0x10e53ce        256  compiler::Compiler::EmitMoveInit()
    @           0xeb3f1d         80  compiler::Compiler::Visit()
    @           0xeb2e0b         96  ast::Visitor<>::ErasedVisit()
    @          0x13cb51c         64  ast::Identifier::Accept()
    @           0xf88bf9         64  ast::Visitor<>::Visit()
    @           0xf7ed70         64  compiler::Compiler::EmitMoveInit()
    @           0xf723db       1056  compiler::Compiler::EmitValue()
    @           0xeb5004         48  compiler::Compiler::Visit()
    @           0xebe03e         48  compiler::Compiler::Visit()
    @           0xebd6cb         64  ast::Visitor<>::ErasedVisit()
    @          0x13cac5c         64  ast::Declaration::Accept()
    @           0xeb1f99         80  ast::Visitor<>::Visit()
    @           0xeafb1e         48  compiler::Compiler::EmitValue()
    @          0x11d4d23        272  compiler::EmitIrForStatements()
    @          0x11d6e1f        240  compiler::ProcessExecutableBody()
    @           0xee651c        560  compiler::ExecutableModule::ProcessNodes()
    @          0x133d866        160  module::BasicModule::AppendNodes()
    @ ... and at least 4 more frames
[1]    138282 abort (core dumped)  ./icarus demo.ic
asoffer commented 3 years ago

This also happens with copies from designated initializers.