Operator_Convert(m as memoryblock) broken?

Following code causes a compile error:

class class1
  sub operator_convert(m as memoryblock)
  end sub
end class

event window1.open
  dim m as memoryblock
  dim c as class1 = m // compile error here : There is more than one method with this name but this does not match any of the available signatures.
end sub

Is it a Xojo bug, or can anyone explain this?

Any workaround?

Do you have other operator_convert functions in that class?

You need to use an instance of MemoryBlock.

Dim mb As New MemoryBlock(8)

No.

Instantiating the memoryblock does not fix the error - it is a compile error whereby the compiler fails to find the operator_convert function.

It appears to be something specifically wrong with memoryblock, because if I replace all memoryblock references by, for example, picture, the code compiles correctly.

I can confirm this. Please file Feedback.

In the meantime, you can change your Operator_Convert to take a string since that auto-converts from a MemoryBlock. I understand that’s not ideal.

Do you happen to have 2 different operator_convert definitions? Maybe one as string the other as memoryblock?
or is it exactly as what you posted?

It’s nothing more than what he posted. I was able to replicate it here.

Tested, confirmed it’s a bug. Yep. This is a breaking bug.

This works:

Public Sub Operator_Convert(rhs As Object)
  If rhs IsA MemoryBlock Then
    m = MemoryBlock(rhs)
  Else
    Raise New InvalidArgumentException("Must use a memoryblock to convert to")
  End If
End Sub

[code]// This will work
Var m As New MemoryBlock(1024)
Var c As Class1 = m

// This won’t work, throws an invalidArgumentException
Var x As New Dictionary
Var b As Class1 = x
[/code]

m is a propert of type MemoryBlock on Class1

Thanks for the replies.

@Derk Jochems Thanks - I hadn’t thought of that.

@Kem Tekinay I posted to feedback as a beta bug, because for unknown reason, Feedback prevented me from specifying Case Type = Bug. The link is : <https://xojo.com/issue/60281>

Yeah, it’s been doing that.