Add typo detection when lookups on SkylarkModules fail.

Also consolidate code with getattr so getattr now also gets typo detection.

PiperOrigin-RevId: 197612666
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index 3610072..3e0db3d 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -1347,7 +1347,9 @@
   public void testStructAccessOfMethod() throws Exception {
     new SkylarkTest()
         .update("mock", new Mock())
-        .testIfExactError("object of type 'Mock' has no field 'function'", "v = mock.function");
+        .testIfExactError(
+            "object of type 'Mock' has no field 'function', however, a method of that name exists",
+            "v = mock.function");
   }
 
   @Test
@@ -1360,6 +1362,15 @@
   }
 
   @Test
+  public void testStructAccessType_nonClassObject() throws Exception {
+    new SkylarkTest()
+        .update("mock", new Mock())
+        .testIfExactError(
+            "object of type 'Mock' has no field 'sturct_field' (did you mean 'struct_field'?)",
+            "v = mock.sturct_field");
+  }
+
+  @Test
   public void testJavaFunctionReturnsMutableObject() throws Exception {
     new SkylarkTest()
         .update("mock", new Mock())