Repository: toml-rs/toml (language: rust)

Issue:
set_dotted(true) on InlineTable doesn't work as expected
```rust
use toml_edit::*;

fn main() {
    let mut d = Document::new();
    d["nixpkgs"] = table();
    d["nixpkgs"]["src"]["git"] = value("https://git");
    d["nixpkgs"]["src"].as_inline_table_mut().unwrap().set_dotted(true);
    println!("{}", d);
}
```
prints
```toml
[nixpkgs]
src = { git = "https://git"}
```



Discussion / hints:
Thinking about this, what's the difference between dotted `InlineTable` and dotted `Table`?
i don't feel confident that i can help clear up the definitions, but i'd like to make my expectations explicit:

```toml
[nixpkgs]
src.git = "https://git"
```

i'm also wondering which table is considered dotted here :thinking: it seems to be a property of the keys in the _nixpkgs_ table rather than in the _src_ table.

```toml
[nixpkgs]
src.git = "https://git"
```
This is the expected output. And this code works:
```rust
use toml_edit::*;

fn main() {
    let mut d = Document::new();
    d["nixpkgs"] = table();
    
    d["nixpkgs"]["src"] = table();
    d["nixpkgs"]["src"].as_table_mut().unwrap().set_dotted(true);
    d["nixpkgs"]["src"]["git"] = value("https://github.com/nixos/nixpkgs");

    println!("{}", d);
}
```
> i'm also wondering which table is considered dotted here thinking it seems to be a property of the keys in the nixpkgs table rather than in the src table.

This is a TOML property, so `src` is a table (dotted), and `git` is the key of that table, see https://toml.io/en/v1.0.0 for details.

EDIT: actually TOML spec talks about dotted keys, not tables. But I in terms implementation, it might be harder to implement as a property of keys.
> Thinking about this, what's the difference between dotted `InlineTable` and dotted `Table`?

Ease of implementation :)

A dotted key in a standard table can have standard tables nested under it
```rust
[fruit]
apple.color = "red"
apple.taste.sweet = true

# [fruit.apple]  # INVALID
# [fruit.apple.taste]  # INVALID

[fruit.apple.texture]  # you can add sub-tables
smooth = true
```

But you can't do that with Inline Tables.

And the way the divide is currently implemented generally makes it easier to convert the data back to a string.  I do have an idea that might allow us to fix this.

Fix patch:
diff --git a/src/inline_table.rs b/src/inline_table.rs
index 9cd8e8bb..b5f90221 100644
--- a/src/inline_table.rs
+++ b/src/inline_table.rs
@@ -44,11 +44,11 @@ impl InlineTable {
     pub fn get_values(&self) -> Vec<(Vec<&Key>, &Value)> {
         let mut values = Vec::new();
         let root = Vec::new();
-        self.get_values_internal(&root, &mut values);
+        self.append_values(&root, &mut values);
         values
     }
 
-    fn get_values_internal<'s, 'c>(
+    pub(crate) fn append_values<'s, 'c>(
         &'s self,
         parent: &[&'s Key],
         values: &'c mut Vec<(Vec<&'s Key>, &'s Value)>,
@@ -58,7 +58,7 @@ impl InlineTable {
             path.push(&value.key);
             match &value.value {
                 Item::Value(Value::InlineTable(table)) if table.is_dotted() => {
-                    table.get_values_internal(&path, values);
+                    table.append_values(&path, values);
                 }
                 Item::Value(value) => {
                     values.push((path, value));
diff --git a/src/table.rs b/src/table.rs
index 44068855..e3d458d4 100644
--- a/src/table.rs
+++ b/src/table.rs
@@ -55,11 +55,11 @@ impl Table {
     pub fn get_values(&self) -> Vec<(Vec<&Key>, &Value)> {
         let mut values = Vec::new();
         let root = Vec::new();
-        self.get_values_internal(&root, &mut values);
+        self.append_values(&root, &mut values);
         values
     }
 
-    fn get_values_internal<'s, 'c>(
+    fn append_values<'s, 'c>(
         &'s self,
         parent: &[&'s Key],
         values: &'c mut Vec<(Vec<&'s Key>, &'s Value)>,
@@ -69,10 +69,18 @@ impl Table {
             path.push(&value.key);
             match &value.value {
                 Item::Table(table) if table.is_dotted() => {
-                    table.get_values_internal(&path, values);
+                    table.append_values(&path, values);
                 }
                 Item::Value(value) => {
-                    values.push((path, value));
+                    if let Some(table) = value.as_inline_table() {
+                        if table.is_dotted() {
+                            table.append_values(&path, values);
+                        } else {
+                            values.push((path, value));
+                        }
+                    } else {
+                        values.push((path, value));
+                    }
                 }
                 _ => {}
             }


Test patch:
diff --git a/tests/test_edit.rs b/tests/test_edit.rs
index 6b18b200..da98b107 100644
--- a/tests/test_edit.rs
+++ b/tests/test_edit.rs
@@ -754,3 +754,44 @@ fn test_inline_table_append() {
     assert!(a.contains_key("e"));
     assert_eq!(b.len(), 3);
 }
+
+#[test]
+fn test_insert_dotted_into_std_table() {
+    given("")
+        .running(|root| {
+            root["nixpkgs"] = table();
+
+            root["nixpkgs"]["src"] = table();
+            root["nixpkgs"]["src"]
+                .as_table_mut()
+                .unwrap()
+                .set_dotted(true);
+            root["nixpkgs"]["src"]["git"] = value("https://github.com/nixos/nixpkgs");
+        })
+        .produces_display(
+            r#"
+[nixpkgs]
+src.git = "https://github.com/nixos/nixpkgs"
+"#,
+        );
+}
+
+#[test]
+fn test_insert_dotted_into_implicit_table() {
+    given("")
+        .running(|root| {
+            root["nixpkgs"] = table();
+
+            root["nixpkgs"]["src"]["git"] = value("https://github.com/nixos/nixpkgs");
+            root["nixpkgs"]["src"]
+                .as_inline_table_mut()
+                .unwrap()
+                .set_dotted(true);
+        })
+        .produces_display(
+            r#"
+[nixpkgs]
+src.git = "https://github.com/nixos/nixpkgs"
+"#,
+        );
+}