Why does Xojo.Core.Dictionary.HasKey(String) work?

Consider this code, which does hit the breakpoint in 2016r1

[code]Dim D As New Xojo.Core.Dictionary
Dim S As String = DefineEncoding(“a”, Nil)
Dim T As Text = “a”

D.Value(T) = T

If D.HasKey(S) Then
Break
End If[/code]

We have a string with nil encoding, which is found in the dictionary, despite the only key being a Text. String should never implicitly convert to Text, and without an encoding, should raise an exception when trying to explicitly convert. So given all this, why are S and T effectively equivalent in this example? This seems like an implied conversion. It’s convenient, no doubt, but I want to make sure I’m not relying on a bug.

This is intentional. The comparisons are mirroring what would happen if it were done with explicit types at compile time:

  Dim S As String = DefineEncoding("a", Nil)
  Dim T As Text = "a"
  
  If s = t Then 
    Break
  End If

Why would s = t if s has no encoding by which to convert to Text? Just trying to understand the reasoning here.

It converts in the other direction. The common type between Text and String is String.

So we’re seeing the implied Text to String conversion, and then String to String comparison here?

Yep.