crystal-community / icr

Interactive console for Crystal programming language
MIT License
506 stars 40 forks source link

Icr shows errors next instruction after calling Dir.mkdir(), Dir.mkdir_p() and Dir.rmdir() #90

Closed crabonature closed 6 years ago

crabonature commented 6 years ago

When I try to use Dir.mkdir() in icr the next instructions always will fail with error complaining about it exists. From source code it's just trying to run mkdir() on every recompilation and thats why error shows.

The same goes for Dir.rmdir() and Dir.mkdir_p().

crabonature@crap:~[130]$ icr

icr(0.24.1) > Dir.mkdir("bla bla")
 => 0

icr(0.24.1) > 1 + 1
Unable to create directory 'bla bla': File exists (Errno)
  from Dir::mkdir<String, Int32>:Int32
  from Dir::mkdir<String>:Int32
  from __icr_exec__:Int32
  from __crystal_main
  from _crystal_main<Int32, Pointer(Pointer(UInt8))>:Nil
  from Crystal::main_user_code<Int32, Pointer(Pointer(UInt8))>:Nil
  from Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32
  from main
jwoertink commented 6 years ago

This is interesting. It seems this works fine for me in version 0.4.0, but I do get this error in 0.5.0. I'm not sure what changed exactly between the two, but that may be worth investigating.

crabonature commented 6 years ago

Strange that it could works before because in code there is reevaluation of whole command stack when every new command is issued, so it was probably always error for second rmdir("xx") evaluation, because this dir was removed at previous instruction evaluation. https://github.com/crystal-community/icr/blob/6dabbef34e3223fe08ff337ded13e873cd369c60/src/icr/executer.cr#L20 This line of execution changed since 0.4.0, because of Crystal changes: https://github.com/crystal-community/icr/blob/6dabbef34e3223fe08ff337ded13e873cd369c60/src/icr/executer.cr#L24

veelenga commented 6 years ago

Please see https://github.com/crystal-community/icr/pull/91#issuecomment-372580944